VBA issue with Mid string function for Excel 2004 for Mac

Ashaelon

New Member
Joined
Aug 30, 2011
Messages
2
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:

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
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Does this work?

Code:
sNewNR = VBA.Mid(oName.RefersTo, InStr(oName.RefersTo, "]") + 1)
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top