Run-time error for different users

Wes4444

New Member
Joined
Dec 7, 2017
Messages
21
Hi,

I added a Macro to my workbook which, when run, takes the current worksheet, saves it as a temporary file, emails it out and then deletes the file. It works fine for me but when another user tries to run it, they get the error message: Run-time error '1004': Method 'SaveAs' of object'_Workbook' failed. When I try to debug the issue the following line is highlighted:

Code:
Sub Email_Button()
If MsgBox("Are you sure?", vbYesNo) = vbNo Then Exit Sub

   Dim oApp As Object
   Dim oMail As Object
   Dim LWorkbook As Workbook
   Dim LFileName As String

   'Turn off screen updating
   Application.ScreenUpdating = False

   'Copy the active worksheet and save to a temporary workbook
   ActiveSheet.Copy
   Set LWorkbook = ActiveWorkbook

   'Create a temporary file in your current directory that uses the name
   ' of the sheet as the filename
   LFileName = LWorkbook.Worksheets(1).Name
   On Error Resume Next
   'Delete the file if it already exists
   Kill LFileName
   On Error GoTo 0
   'Save temporary file
   [COLOR=#ff0000]LWorkbook.SaveAs Filename:=LFileName[/COLOR]

   'Create an Outlook object and new mail message
   Set oApp = CreateObject("Outlook.Application")
   Set oMail = oApp.CreateItem(0)

   With oMail
   .Display
   End With
   Signature = oMail.body
   With oMail
      .To = "..."
       .Subject = "Measurement Report - " & Format(Date, "dd/mm/yyyy")
      .Attachments.Add LWorkbook.FullName
      .body = "Hi All," & vbNewLine & vbNewLine & _
                         "Please see attached measurement report for " & Format(Date, "dd/mm/yyyy.") & vbNewLine & vbNewLine & _
                         "Kind Regards," & Signature
      .Send
   End With

   'Delete the temporary file and close temporary Workbook
   LWorkbook.ChangeFileAccess Mode:=xlReadOnly
   Kill LWorkbook.FullName
   LWorkbook.Close SaveChanges:=False

   'Turn back on screen updating
   Application.ScreenUpdating = True
   Set oMail = Nothing
   Set oApp = Nothing

End Sub

Is this just an issue for the user and their preferences etc. or is there an issue in the coding?

Any help will be much appreciated.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Does the user have write access to the folder you are using?
 
Upvote 0
Thanks for your reply. I haven't used an folder structure in the macro that requires any access have I? The macro saves the worksheet as a temproary file, attaches it to the email and then deletes it so there isn't any folder structures needed? Correct me if I am wrong of course.
 
Upvote 0
Well the saveas puts the temporary file in whatever the current folder is, so the user must have rights to that folder.
 
Upvote 0
OK a bit stumped then. You could put a breakpoint in on the saveas, then kill the macro and try doing the saveas manually to see if you get more info.
 
Upvote 0
Wes4444

You should specify the folder and the file format, the folder because you can't guarantee what the current directory is the file format because VBA sometimes doesn't like it if you don't use the correct format.
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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