Save as PDF VBA not working...

Jav_uk8

New Member
Joined
Jan 12, 2017
Messages
22
Hi All,

I am trying to create a macro to go through a list of dates (reports) and save them individually as PDFs in my area.

I get the following error:

Run-time error '1004':

Document not saved. the document may be open, or an error may have been encountered when saving.


Below is the macro used, I have used this macro before on a different report and it worked.


Sub Printing()

For i = 35 To 294
Sheets("Merthyr Printout").Select
Cells(81, 8) = Cells(i, 34)

Post_Script


Next i
End Sub


Sub Post_Script()


Sheets("Merthyr Printout").Select


crit = Cells(3, 34)
'Sheets("Merthyr Printout").Select


Dim temp As String
temp = "W:\People Report\Reports\Merthyr\Printout" & crit & ".pdf"


'ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=temp, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False



End Sub


Please help!!!

Cheers,

Jav
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Welcome to the forum! When posting code, please do so between code tags. Click the # icon on toolbar to insert the tags.

Does temp contain a legal filename. When working with dates, "/" and "" mean folder delimiter. That is seldom what was intended.

e.g.
Code:
temp = "W:\People Report\Reports\Merthyr\Printout " & _
  Format(crit, "mm-dd-yyyy") & ".pdf"
Debug.Print temp
After you run code, Debug.Print shows results in the Immediate window. Select View to enable it if needed.
 
Upvote 0
The code below is what I am using, the only problem now is every report run is saving as the same date (30/12/2016).

How do I continue the loop through the dates?

Code:
Sub Printing()                                              
       For i = 3 To 263
       Sheets("Merthyr Printout").Select
       Cells(81, 8) = Cells(i, 34)
       
 Post_Script


Next i
End Sub


Sub Post_Script()


crit = Cells(3, 34) 'For new dates, this will have to be amended.
Sheets("Merthyr Printout").Select




temp = "W:\People Report\Reports\Merthyr\Printout\ " & _
    Format(crit, "dd-mm-yyyy") & ".pdf"
    Debug.Print temp


ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=temp, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False


path = "W:\People Report\Reports\Merthyr\Printout\" & crit & ".pdf"
            
End Sub

Cheers,

Jav
 
Upvote 0

Forum statistics

Threads
1,214,570
Messages
6,120,296
Members
448,954
Latest member
EmmeEnne1979

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