Excel to save as pdf did not save

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,738
Office Version
  1. 2007
Platform
  1. Windows
Hi,
Code supplied below but when i run it to save as a pdf file the line shown below in in yellow.

.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True


Code:
Private Sub GrassSummarySheet_Click()    Dim strFileName As String
    
       strFileName = "C:\Users\Ian\Desktop\GRASS CUTTING\CURRENT GRASS SHEETS\SUMMARY 2019-2020\" & Range("L3") & ".pdf"
       
    If Dir(strFileName) <> vbNullString Then
        MsgBox "GRASS SUMMMARY SHEET " & Range("L3") & " WAS NOT SAVED AS IT ALREADY EXISTS", vbCritical + vbOKOnly, "GRASS SUMMARY SHEET MESSAGE"
        Exit Sub
    End If
    
    With ActiveSheet
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True
        MsgBox "GRASS SUMMARY SHEET " & Range("L3") & " WAS  SAVED SUCCESSFULLY", vbInformation + vbOKOnly, "GRASS SUMMARY SHEET MESSAGE"
        Range("D5:E17,D21:D33").ClearContents
        Range("D5").Select
        ActiveWorkbook.Save
    End With
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi,
Code supplied below but when i run it to save as a pdf file the line shown below in in yellow.

.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True


Code:
Private Sub GrassSummarySheet_Click()    Dim strFileName As String
    
       strFileName = "C:\Users\Ian\Desktop\GRASS CUTTING\CURRENT GRASS SHEETS\SUMMARY 2019-2020\" & Range("L3") & ".pdf"
       
    If Dir(strFileName) <> vbNullString Then
        MsgBox "GRASS SUMMMARY SHEET " & Range("L3") & " WAS NOT SAVED AS IT ALREADY EXISTS", vbCritical + vbOKOnly, "GRASS SUMMARY SHEET MESSAGE"
      [COLOR=#ff0000][B]  Exit Sub[/B][/COLOR]
    End If
    
    With ActiveSheet
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True
        MsgBox "GRASS SUMMARY SHEET " & Range("L3") & " WAS  SAVED SUCCESSFULLY", vbInformation + vbOKOnly, "GRASS SUMMARY SHEET MESSAGE"
        Range("D5:E17,D21:D33").ClearContents
        Range("D5").Select
        ActiveWorkbook.Save
    End With
End Sub
Comment out the Exit Sub line so you don't exit the sub prior to the save as pdf.
 
Upvote 0
What do you have in the Range cell ("L3"), Do you have a date?, what does the error message say?
 
Upvote 0
Hi,
Comment out, does that mean delete the Exit Sub text ?

L3 was the problem as it should of been C3
 
Upvote 0
Or do you mean like this, please advise.

Code:
MsgBox "GRASS SUMMARY SHEET " & Range("C3") & " WAS NOT SAVED AS IT ALREADY EXISTS", vbCritical + vbOKOnly, "GRASS SUMMARY SHEET MESSAGE"    
    ' Exit Sub Comment Out
        Exit Sub
    End If
    
    With ActiveSheet
 
Last edited:
Upvote 0
Or do you mean like this, please advise.

Code:
MsgBox "GRASS SUMMARY SHEET " & Range("C3") & " WAS NOT SAVED AS IT ALREADY EXISTS", vbCritical + vbOKOnly, "GRASS SUMMARY SHEET MESSAGE"    
    ' Exit Sub Comment Out
        Exit Sub
    End If
    
    With ActiveSheet
Ignore - my error, read the If statement too quickly.
 
Upvote 0
L3 had the command button on it and i should have entered C3 anyway,now it works.
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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