Hi Guys,
I have created a VBA which saves the active sheet of the specific workbook - this works perfectly but I also want to save the whole workbook alongside the PDF with the same filename as the PDF.
How can I fit this in on the same macro? Please see below code:
Super thanks in advance!
I have created a VBA which saves the active sheet of the specific workbook - this works perfectly but I also want to save the whole workbook alongside the PDF with the same filename as the PDF.
How can I fit this in on the same macro? Please see below code:
VBA Code:
Sub PDFActiveSheet()
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
On Error GoTo errHandler
Set wbA = ActiveWorkbook
Set wsA = ActiveSheet
strTime = Format(Now(), "ddmmyy")
'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"
'set save name
strName = wsA.Range("N7").Value _
& " - " & wsA.Range("N8").Value _
& " - " & wsA.Range("N9").Value
'create default name for savng file
strFile = strName & "" & strTime & ".pdf"
strPathFile = strPath & strFile
'use can enter name and
' select folder for file 'currently set to active folder
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strPathFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")
'export to PDF if a folder was selected
If myFile <> "False" Then
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
'confirmation message with file info
MsgBox "PDF file has been created: " _
& vbCrLf _
& myFile
End If
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End Sub
Super thanks in advance!