I'm struggling trying to close other workbooks using VBA. I have a template that opens another file, copies elements of that workbook and pastes it into the current template.
The primary problem I have is setting the workbook name of the data file as a variable. I've tried to set a variable with the file name after the data file has been activated with the following code:
When I try that I get an error stating "Run-time error '91': Object variable or With block variable not set".
Consequently I'm not able to get to a point where I can say:
Additionally I'm not able to use a variable name for the current file, so as I switch between the data source and the template I have to hard code the file name. I'd like to have this as a variable value so each saved version doesn't require recoding.
Any insight would be appreciated. Thanks!
The primary problem I have is setting the workbook name of the data file as a variable. I've tried to set a variable with the file name after the data file has been activated with the following code:
HTML:
Dim DataSource As Workbook
DataSource = ActiveWorkbook.Name
When I try that I get an error stating "Run-time error '91': Object variable or With block variable not set".
Consequently I'm not able to get to a point where I can say:
HTML:
DataSource.Close Savechanges:=False
Additionally I'm not able to use a variable name for the current file, so as I switch between the data source and the template I have to hard code the file name. I'd like to have this as a variable value so each saved version doesn't require recoding.
Any insight would be appreciated. Thanks!