Reputation: 3916
In Excel I am writing a macro to move and format data between two files. I begin by opening the first file and running a macro that allows you to choose a file.
I am opening a file using this code:
myFileName= Application.GetOpenFilename(filefilter:="All Files, .", Title:="All Files")
I then follow it with this code:
Workbooks.Open Filename:=myFileName
Later in the code Module, I would like to copy and past things between this newly opened file and the one I ran the macro from inside. Currently I am having to hard code their names like so:
Windows("data.xlsx").Activate
How can I store the name of the newly opened file in a string and how can I get the name of the excel file I am in into a string?
Thanks
Upvotes: 0
Views: 94
Reputation: 1559
Before opening the second workbook assign the name of the current workbook to a variable:
nameFirstWorkbook = ActiveWorkbook.Name
You already get the name of the second workbook from the open file dialog.
Upvotes: 0