(VB) Closing Workbook with Dynamic Name?
Hi,
I'm working on a sheet where a user specifies a source file to be used to generate additional formatted sheets. I have a macro that generates said sheets and opens the source file to allow them to populate, but I can't figure out how to get the source workbook to close.
Here's how I open the source workbook:
Dim wSh As Excel.Worksheet
Set wSh = ActiveWorkbook.Sheets("Lists Formulas")
Workbooks.Open Filename:=wSh.Range("'Lists Formulas'!E3") & wSh.Range("'Lists Formulas'!E6")
Lists Formulas'!E3 is the filepath and Lists Formulas'!E6 is the source file the user selects. I've tried a few methods of closing it, for example:
Workbooks(wSh.Range("'Lists Formulas'!E6")).Close SaveChanges:=False
or
Workbooks.Close Filename:=wSh.Range("'Lists Formulas'!E3") & wSh.Range("'Lists Formulas'!E6") SaveChanges:=False
I tried a few other things, like defining the Filename for the Open as a variable and string, but haven't gotten anywhere. The overall macro is working just fine right now except that I can't close that source workbook.
Edit: I'm using Excel on an Office 365 sub.
Posted Jan 28, 2022, 4:18 PM UTC · edited
u/Siendra - Your post was submitted successfully.
Solution Verifiedto close the thread.Failing to follow these steps may result in your post being removed without warning.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.