Jump to content

FileDialogOpen with Excel


Recommended Posts

Hi,

 

was searching in the forum for solution but didn't found anything similar, so my problem is that after user selects Excel file the other _Excel_ functions doesn't work.

 

I created a logic, that if any user changes file name or file location then has option to select the file location manually with FileDialogOpen

 

This is how it looks:

$fileLocation = "C:\Users\Desktop\File.xlsx"

If Not FileExists($fileLocation) Then
    MsgBox(48, "File not found", "File not found, please select")
    FileOpenDialog("Select file", "C:\Users\", "Excel (*.xlsx*)")
EndIf

    $oExcel = _Excel_Open(1, 1, 1, 1, 1)
    $xlBook = _Excel_BookOpen($oExcel, $fileLocation)
    $xlBook.Sheets("Users").Activate 
    
    .....and continues other $xlBook.Sheets functions.......

 

So if the File.xlsx is found on this location everything works correctly the sheet .Active works as expected, but if the File.xlsx not found and user selects in other directory same file, then all my $xlBook.Sheets functions doesn't work and crashes on first one which is $xlBook.Sheets("Users").Activate 

 

What did I missed?

 

Thank you for the help :)

 

Link to post
Share on other sites

Well... $fileLocation never changes. You probably meant to set it equal to the result of the FileOpenDialog 

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Link to post
Share on other sites

If you had put some error handling after each statements, you would have found out what was the problem.  Look in help file under Excel UDF to learn how to insert messages that check for errors (in all examples there is error handling).

Edited by Nine
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...