Share via

Excel VBA run-time error 1004 "Application-defined or object-defined error"

Anonymous
2016-01-08T18:55:27+00:00

Dear All,

I have a macro to save excel sheet to pdf.

Sub DelieveryNotePDF()

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _

fileName:="Users:Shall:Library:Mobile Documents:com~apple~CloudDocs:Delievery Note:" & Range("g2").Value & " " & Format(Now, "dd/mm/yyyy") _

    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _

    :=False, OpenAfterPublish:=True

End Sub

It works fine but after i press control+p to print a sheet & after that when i want to use the macro it doesn't work and i get the "run-time error 1004 : Application-defined or object-defined error".

I am using office for mac 2011.

waiting for your help

thankssss.....

Microsoft 365 and Office | Excel | For home | MacOS

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2016-01-10T15:30:01+00:00

    yes i tried debuging it, but i get all the lines below in yellow Highlight

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _

    fileName:="Users:Shall:Library:Mobile Documents:com~apple~CloudDocs:Delievery Note:" & Range("g2").Value & " " & Format(Now, "dd/mm/yyyy"), _

        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _

        :=False, OpenAfterPublish:=False

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-01-09T19:48:30+00:00

    Have you tried to debug it?: Which line causes the error?

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-01-09T15:44:27+00:00

    Yes i am sure of that, i have macro assigned to a button on multiple sheets and they all work but after printing a sheet none of them work. And i get that runtime error

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2016-01-09T14:10:43+00:00

    It looks like your macro opens the sheet after it is saved. So, you need to be sure the correct sheet is active when you run the macro.

    Was this answer helpful?

    0 comments No comments