deadserious Posted October 11, 2012 Share Posted October 11, 2012 I'm wondering if anyone can help me with this, I have a need to write a script that will allow me to open 2 Excel files, copy the value in some of the fields and paste it into another Excel file. I'm able to open the Excel files, however I cannot bring to focus the Excel file where I need to paste the info in I'm using (WinActivate) I'm not sure how to find out the file name after running the FileOpenDiolog command, it gives me the full file path and I only need the name of the file and don't really understand how to call it. Here is my code so far, please let me know what I can be doing wrong... thx so much ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Script Start - #include <Excel.au3> $message = "Please Browse to Excel Utility Calculations the Month you will be working on." $uCalc = FileOpenDialog($message, @ScriptDir & "\", "Images (*.xls; *.xlsx)", 1) ; Opens dialog box to search for Utility Calculation Excel file. If @error Then MsgBox(4096,"","No File(s) chosen") Else $uCalc = StringReplace($uCalc, "|", @CRLF) MsgBox(0,"Please Verify this is the Utility Calculations File current month","You chose the following spreadsheet " & $uCalc) EndIf $oExecel = _ExcelBookOpen($uCalc) If @error = 1 Then MsgBox(0, "Error!", "Unable to Create the Excel Object") Exit ElseIf @error = 2 Then MsgBox(0, "Error!", "File does not exist - Please Try Again!") Exit EndIf $message2 = "Please Browse to Excel Meter Read." ; Opens Second dialog box to search for Meter Read Excel File. $mRead = FileOpenDialog($message2, @ScriptDir & "\", "Images (*.xls; *.xlsx)", 1) If @error Then MsgBox(4096,"","No File(s) chosen") Else $mRead = StringReplace($mRead, "|", @CRLF) ; this is where I'm taking the information from **************************** MsgBox(4096,"This should be the Meter Read Excel File.","You chose " & $mRead) EndIf $oExecel2 = _ExcelBookOpen($mRead) If @error = 1 Then MsgBox(0, "Error!", "Unable to Create the Excel Object") Exit ElseIf @error = 2 Then MsgBox(0, "Error!", "File does not exist - Please Try Again!") Exit EndIf ; End of opening Excel Files. ; Attempt to read file cells $sCellValue = _ExcelReadCell($oExecel2, 2, 2) ;Reads Meter Read Excel File Cell B2 and displays in dialog box. MsgBox(0,"", "Corp Yard: " & $sCellValue) MsgBox(0, "", $uCalc) WinActivate("[CLASS:XLMAIN]", $uCalc) Link to comment Share on other sites More sharing options...
water Posted October 11, 2012 Share Posted October 11, 2012 Please have a look at function _PathSplit. Splits a path into the drive, directory, file name and file extension parts. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now