Saving file on a network drive where the drive letter varies between users

acombest

Board Regular
Joined
May 8, 2017
Messages
136
This is the code I have but it really only works when the user has the L: drive which is not always the case. How do I save a file when I users all have different drive letters? Also why doesn't my error handling work? I feel like I don't fully understand how to structure the error handling. All help is greatly appreciated. Thanks

Code:
On Error GoTo alt
wb.SaveAs "L:\AJ's Inventory Project\McKesson Orders\" & workbookname
Ignoreme = 0
If Ignoreme = 1 Then
alt:
On Error Resume Next
wb.SaveAs "S:\AJ's Inventory Project\McKesson Orders\" & workbookname
End If
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Code:
Sub SaveToNetwork()
  Dim fp, wb As Workbook, fso As Object, workbookname As String
  
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set wb = ActiveWorkbook
  workbookname = wb.Name

  Select Case True
    Case fso.folderexists("L:\AJ's Inventory Project\McKesson Orders\")
      fp = "L:\AJ's Inventory Project\McKesson Orders\"
    Case fso.folderexists("S:\AJ's Inventory Project\McKesson Orders\")
      fp = "S:\AJ's Inventory Project\McKesson Orders\"
    Case Else
      fp = False
  End Select
  
  If Not fp Then
    MsgBox "No file path found.", vbCritical, "Macro Ending"
    Exit Sub
  End If
  
  wb.SaveAs fp & workbookname
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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