excel vba save worksheet as pdf.

BRB1983

Board Regular
Joined
Aug 29, 2019
Messages
61
I'm having issues with this code not saving my file. I get an error 1004. it worked before. does any one see any issues with this code?
Code:
Option Explicit
Sub SaveAsPDF()

 Dim strDir As String
   strDir = CreateObject("WScript.Shell").specialfolders("Desktop") & "\Daily Reports\"
     
    If Dir(strDir, vbDirectory) = "" Then
        MkDir strDir
    Else
        'MsgBox "Directory exists."
    End If
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
Dim fName As String
With ActiveSheet
    fName = .Range("C7").Value & " " & .Range("F46").Value
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            strDir & fName, Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
MsgBox "SAVE COMPLETE"
Range("C7") = ""
Range("C9:C45") = ""
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
i think i know the proble.. cell C7 is date format... can not save a file with "/". ill give it a try with out date.

Then, try this


Code:
fName = format(.Range("C7").Value, "dd-mm-yyyy") & " " & .Range("F46").Value
 
Upvote 0

Forum statistics

Threads
1,224,743
Messages
6,180,687
Members
452,994
Latest member
Janick

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