Excel to save as pdf did not save

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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,215,219
Messages
6,123,692
Members
449,117
Latest member
Aaagu

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