Open a module in another workbook using server name

hawley

Board Regular
Joined
Apr 7, 2002
Messages
197
I have a workbook that will open and if certain condtions are meet will open another workbook and run a specific module. I can get this to work when I use the drive letter but I would like to use the serve name instead. Any ideas. My first example is using the drive letter and it works. My second example is using the server name and it is not working. I get a run-time error'1004': The macro "//buying/share/share/MPA/ALL/MIO/Code Changes/Kitchen Sink/UpdateVersion1.xls'!current' cannot be found.

Example that works with drive letters
Code:
Dim strFilePath As String, strFilePath2 As String

    strFilePath = "G:\share\MPA\ALL\MIO\Code Changes\Kitchen Sink\UpdateVersion1.xls"
    strFilePath2 = "G:/share/MPA/ALL/MIO/Code Changes/Kitchen Sink/UpdateVersion1.xls"

    If Dir(strFilePath, vbDirectory) = vbNullString Then
        strFilePath = "Q:\share\MPA\ALL\MIO\Code Changes\Kitchen Sink\UpdateVersion1.xls"
        strFilePath2 = "Q:/share/MPA/ALL/MIO/Code Changes/Kitchen Sink/UpdateVersion1.xls"
        If Dir(strFilePath, vbDirectory) = vbNullString Then
            MsgBox ("Code update was not successful.  Please contact MIO.Business Solutions.")
            GoTo Finish
        End If
    End If

    Set mcro = Workbooks.Open(strFilePath, False)
    changedwb.Activate
    Application.Run "'" & strFilePath2 & "'!current"
    mcro.Close False
    GoTo Finish

Example that does not work with server names.
Code:
Dim strFilePath As String, strFilePath2 As String

    strFilePath = "\\buying\share\share\MPA\ALL\MIO\Code Changes\Kitchen Sink\UpdateVersion1.xls"
    strFilePath2 = "//buying/share/share/MPA/ALL/MIO/Code Changes/Kitchen Sink/UpdateVersion1.xls"

    If Dir(strFilePath, vbDirectory) = vbNullString Then
        MsgBox ("Code update was not successful.  Please contact MIO.Business Solutions.")
        GoTo Finish
    End If

    Set mcro = Workbooks.Open(strFilePath, False)
    changedwb.Activate
    Application.Run "'" & strFilePath2 & "'!current"
    mcro.Close False
    GoTo Finish
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I found out I can do it this way instead.

Code:
Dim strFilePath As String

    strFilePath = "\\buying\share\share\MPA\ALL\MIO\Code Changes\Kitchen Sink\UpdateVersion1.xls"

    If Dir(strFilePath, vbDirectory) = vbNullString Then
        MsgBox ("Code update was not successful.  Please contact MIO.Business Solutions.")
        GoTo Finish
    End If

    Set mcro = Workbooks.Open(strFilePath, False)
    changedwb.Activate
    Application.Run "'UpdateVersion1.xls'!current"
    mcro.Close False
    GoTo Finish

If there are any other ways to do this please let me know. Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,567
Messages
6,179,571
Members
452,927
Latest member
whitfieldcraig

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