Hi All,
I have a module run from access that does a few things then opens an excel file and runs a macro on that excel spreadsheet. Running the excel macro from both excel and access worked perfectly fine. I realised that one of the excel files that will be opened as part of the excel macro may already be open by the user (it's only one user that will have the file open so don't need to worry about others having it open) when the code is run. So I tried to add in a bit of code which would close that workbook at the beginning of the excel macro and the rest will run after that workbook has closed.
I went for this method:
This works perfectly fine when I just open the excel file and run the macro manually through that. But as soon as I go to run the macro through the access module it will give me "Subscript out of range" on the first line of the above code.
The file is definitely spelt correctly as I copied the name when the file is referenced later in the code (and works fine). The file is definitely open when I try to run the code.
I've tried the whole file path and file name with and without the file extension and tried just the filename with and without extension but no luck.
I have also tried closing the workbook in the access module but was getting the same error message no matter which method I used to try and accomplish it.
Any suggestions would be appreciated and many thanks in advance.
I have a module run from access that does a few things then opens an excel file and runs a macro on that excel spreadsheet. Running the excel macro from both excel and access worked perfectly fine. I realised that one of the excel files that will be opened as part of the excel macro may already be open by the user (it's only one user that will have the file open so don't need to worry about others having it open) when the code is run. So I tried to add in a bit of code which would close that workbook at the beginning of the excel macro and the rest will run after that workbook has closed.
I went for this method:
Code:
Workbooks("Invoice Register COPY.xls").Activate
ActiveWorkbook.Close
The file is definitely spelt correctly as I copied the name when the file is referenced later in the code (and works fine). The file is definitely open when I try to run the code.
I've tried the whole file path and file name with and without the file extension and tried just the filename with and without extension but no luck.
I have also tried closing the workbook in the access module but was getting the same error message no matter which method I used to try and accomplish it.
Any suggestions would be appreciated and many thanks in advance.