jeffspringer
New Member
- Joined
- Dec 2, 2015
- Messages
- 3
I have a macro that works for the 2011 version of Excel for Mac, but causes a Subscript out of Range error on the 2016 version of Excel.
The error occurs on the following line:
After some experimentation, I'm pretty sure that it's because the 2011 version of Excel for Mac requires the extension (".xlsm") but the 2016 version does not. I wish I could just remove the extension, but the macro also needs to work on the PC version of Excel. The PC version of Excel requires the extension.
Due to the differences in file structure between Mac and PC, I've had to test for the operating system with the following code:
So, my first thought was to create the same if/then statement for the line that's causing the error. However, there are 13 different files this macro needs to reference and select throughout the run. So, I thought to simply define variables for each of the files and set the variables at the beginning based upon the operating system.
But then, I thought, "What happens when the next version of Excel comes out and everything breaks again?
So, I'm hoping someone might have a more elegant way of handling this problem.
Thank you!
The error occurs on the following line:
Code:
Windows("METRCMJF Reconciliation.xlsm").Activate
After some experimentation, I'm pretty sure that it's because the 2011 version of Excel for Mac requires the extension (".xlsm") but the 2016 version does not. I wish I could just remove the extension, but the macro also needs to work on the PC version of Excel. The PC version of Excel requires the extension.
Due to the differences in file structure between Mac and PC, I've had to test for the operating system with the following code:
Code:
Dim TheOS As String
TheOS = Application.OperatingSystem
If Left(TheOS, 7) = "Windows" Then
Workbooks.Open Filename:=ThisWorkbook.Path & "\RawData\PlantsInventoryReport-1.xls"
Else
Workbooks.Open Filename:=ThisWorkbook.Path & ":RawData:PlantsInventoryReport-1.xls"
End If
So, my first thought was to create the same if/then statement for the line that's causing the error. However, there are 13 different files this macro needs to reference and select throughout the run. So, I thought to simply define variables for each of the files and set the variables at the beginning based upon the operating system.
But then, I thought, "What happens when the next version of Excel comes out and everything breaks again?
So, I'm hoping someone might have a more elegant way of handling this problem.
Thank you!