Question

I'm trying to work out if it's possible to open a workbook using the file open dialog box and "store" it in a global variable so that it can be accessed by several subroutines.

I have Workbooks.Open Filename:=FileToOpen which works fine to open a workbook and I have declared a public variable like Public wb As Workbookbook. But when I try to assign one to t'other by doing wb=Workbooks.Open Filename:=FileToOpen or Set wb=Workbooks.Open Filename:=FileToOpen I get "Compile error. Expected end of statement" highlighting the Filename

Can anyone tell me if this is possible and if so the best way to approach it??

(Basically what I'm trying to achieve is to be able run a small piece of VBA that rearranges data in a csv file in the most "fool proof" (user proof) way possible. As you can't make VBA standalone .exe I was thinking: auto run a macro that opens a userform with a single button. Click the button and choose a csv, my code runs, saves the csv and closes it. Any other suggestions for this appreciated!)

Was it helpful?

Solution

If you trying to assign result to variable, you should use parentheses:

Set wb = Workbooks.Open(Filename:=FileToOpen)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top