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
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Kenneth Hobson

Well-known Member
Joined
Feb 6, 2007
Messages
3,108
Office Version
  1. 365
Platform
  1. Windows
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.
 

Jav_uk8

New Member
Joined
Jan 12, 2017
Messages
22
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,569
Messages
5,596,918
Members
414,110
Latest member
docops

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
Top