If error finding and saving to desktop path

sdoppke

Well-known Member
Joined
Jun 10, 2010
Messages
647
Hi everyone I have a script that finds the desktop path and save a file there for me (see below) I have found out some users have insufficient admin rights and saving to the desktop willnot be an option. Could someone help me edit this function/script to bring up a message box if this happens (error) and then it will close the file without saving (kick them off)

Thank a ton in advacne for any help. :)

sd

Code:
Function GetDesktopPath() As String
  Dim DskTop As String
  Dim WSH As Object
 
    Set WSH = CreateObject("WScript.Shell")
    DskTop = WSH.SpecialFolders("desktop")
 
    GetDesktopPath = DskTop
 
   'Free the object reference and memory allocated
    Set WSH = Nothing
 
End Function

Code:
Private Sub CommandButton1_Click()
     'Saves filename as value of A1 plus the current date
Store = Sheets("MyStoreInfo").Range("C2")
    Dim newFile As String, fName As String, sName As String
     ' Save to the User's Desktop
      ActiveWorkbook.SaveAs Filename:=Store & "WFMScheduleTool" & ".xlsm"
SaveWFMTool.Hide
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Maybe:
Code:
Private Sub CommandButton1_Click()
On Error GoTo ErrorPresent
     'Saves filename as value of A1 plus the current date
Store = Sheets("MyStoreInfo").Range("C2")
    Dim newFile As String, fName As String, sName As String
     ' Save to the User's Desktop
      ActiveWorkbook.SaveAs Filename:=Store & "WFMScheduleTool" & ".xlsm"
SaveWFMTool.Hide
Exit Sub
ErrorPresent:
MsgBox "Can't Save"
End Sub
 
Upvote 0
Maybe:
Code:
Private Sub CommandButton1_Click()
On Error GoTo ErrorPresent
     'Saves filename as value of A1 plus the current date
Store = Sheets("MyStoreInfo").Range("C2")
    Dim newFile As String, fName As String, sName As String
     ' Save to the User's Desktop
      ActiveWorkbook.SaveAs Filename:=Store & "WFMScheduleTool" & ".xlsm"
SaveWFMTool.Hide
Exit Sub
ErrorPresent:
MsgBox "Can't Save"
End Sub


Brilliant!! thanks for helpin out!!
sd
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,673
Members
452,937
Latest member
Bhg1984

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