Jump to content
Sign in to follow this  
deadserious

get value of file name when using fileopendialog

Recommended Posts

deadserious

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)

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×