I seem to be having a strange problem with the Mid function not working in Excel 2004 for Mac. I developed my VBA code in Office 2007 on Windows 7. I then learned that Office 2004 for Mac was based on VBA5, so I proceeded in making changes to the code to compensate. Now, when I have the user test it on their Mac, they get the object or library not found error with Mid highlighted. I have searched and searched and searched for an answer, but cannot find one. Please help.
Here is the procedure that I am getting the error on:
The specific line that is being shown as the error is:
sNewNR = Mid(oName.RefersTo, InStr(oName.RefersTo, "]") + 1)
TIA
Here is the procedure that I am getting the error on:
Code:
Function CopyTemplate() As Boolean
Dim sFileName As Variant
Dim xlObj As Object 'late bind
Dim xlWB As Object 'late bind
Dim xlWS As Object 'late bind
Dim oName As Object 'late bind
'Dim xlWB As Excel.Workbook 'early bind
'Dim xlWS As Excel.Worksheet 'early bind
'Dim oName As Name 'early bind
Dim sNewNR As String 'Named Range
Dim bRunAll As Boolean
Dim i As Integer 'iterator
bRunAll = False
sFileName = Application.GetOpenFilename("Excel Files (*.xls), *.xls", , "Select the template file...", , False)
If Not sFileName = False Then
Application.ScreenUpdating = False
Set xlObj = GetObject(, "Excel.Application") 'late bind
Set xlWB = xlObj.Workbooks.Open(sFileName) 'late bind
'Set xlWB = Excel.Workbooks.Open(sFileName) 'early bind
For Each xlWS In xlWB.Worksheets
xlWS.Copy After:=ThisWorkbook.Worksheets(ThisWorkbook.Sheets.Count)
Next
Else
Exit Function
End If
ThisWorkbook.Worksheets("Main").Activate
Application.ScreenUpdating = True
xlWB.Close
Application.Calculation = xlCalculationManual
For Each oName In ThisWorkbook.Names
sNewNR = Mid(oName.RefersTo, InStr(oName.RefersTo, "]") + 1)
oName.RefersTo = sNewNR
Next
Application.Calculation = xlCalculationAutomatic
CopyTemplate = True
End Function
The specific line that is being shown as the error is:
sNewNR = Mid(oName.RefersTo, InStr(oName.RefersTo, "]") + 1)
TIA