So I have a file named "Daily Summary.xlsm" when I use my button to save my file as a PDF, my code wants to name it "DailySummary_10xx22" with no space. I really need that space between Daily and Summary in there. I've tried fixing it but I'm not sure how to get my space in there. Any help would be most appreciated. My code is below:
VBA Code:
Sub Save_PDF_with_Prompt()
Dim xWs As Worksheet
Dim xWb As Workbook
Dim xTime As String
Dim xName As String
Dim xPath As String
Dim xFile As String
Dim yPathFile As String
Dim zFile As Variant
On Error GoTo errHandler
Set xWb = ActiveWorkbook
Set xWs = ActiveSheet
xTime = Format(Date - 1, "mm.dd.yyyy")
xPath = xWb.Path
If xPath = "" Then
xPath = Application.DefaultFilePath
End If
xPath = xPath & "\"
xName = Replace(xWs.Name, " ", "")
xName = Replace(xName, ".", "_")
xFile = xName & "_" & xTime & ".pdf"
yPathFile = xPath & xFile
zFile = Application.GetSaveAsFilename _
(InitialFileName:=yPathFile, _
FileFilter:="PDF Format (*.pdf), *.pdf", _
Title:="Save As a PDF File")
If zFile <> "False" Then
xWs.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=zFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
MsgBox "Successfully Saved As a PDF: " _
& vbCrLf _
& zFile
End If
exitHandler:
Exit Sub
errHandler:
MsgBox "Failed to Save"
Resume exitHandler
End Sub