indiglo
New Member
- Joined
- May 27, 2024
- Messages
- 1
- Office Version
- 365
- 2021
- 2019
- 2016
- Platform
- Windows
- MacOS
I'm in need of some help please and thank you.
I have to submit a timesheet for work every week.
It must be submitted by emailing a pdf of the completed timesheet (complete by hand then scan then email).
In 2020, I re-created the timesheet into a spreadsheet and created a VBA macro so that a single button click would perform 2 functions: (1) export a specified range of cells (print area) into a PDF (2) set filename of the newly created pdf to the value of a specified cell. I really value both functions.
I have been using it successfully for years on Microsoft Excel.
A few months ago the script stopped working on Excel at home (no idea why, I never changed it). This would be the latest M365 version.
My workplace uses Excel 2016, and the script works fine there.
I was hoping I could get some help ammending or re-writing the script so it works on Excel (versions 2016+) across both Windows and MacOS.
The script below is what I used - it was lifted from another site/forum - I can't remember where:
The cell with the filename value is held in the "Data" worksheet.
The print area range is held in the "Timesheet" worksheet, which should be set as ActiveSheet.
I have to submit a timesheet for work every week.
It must be submitted by emailing a pdf of the completed timesheet (complete by hand then scan then email).
In 2020, I re-created the timesheet into a spreadsheet and created a VBA macro so that a single button click would perform 2 functions: (1) export a specified range of cells (print area) into a PDF (2) set filename of the newly created pdf to the value of a specified cell. I really value both functions.
I have been using it successfully for years on Microsoft Excel.
A few months ago the script stopped working on Excel at home (no idea why, I never changed it). This would be the latest M365 version.
My workplace uses Excel 2016, and the script works fine there.
I was hoping I could get some help ammending or re-writing the script so it works on Excel (versions 2016+) across both Windows and MacOS.
The script below is what I used - it was lifted from another site/forum - I can't remember where:
VBA Code:
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Option Explicit
Sub SaveAsPDF()
Dim wSheet As Worksheet
Dim vFile As Variant
Dim sFile As String
Set wSheet = ActiveSheet
sFile = Worksheets("Data").Range("F2")
sFile = ThisWorkbook.Path & "\" & sFile
vFile = Application.GetSaveAsFilename _
(InitialFileName:=sFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")
If vFile <> "False" Then
wSheet.Range("A1:S38").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=vFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
End Sub
The cell with the filename value is held in the "Data" worksheet.
The print area range is held in the "Timesheet" worksheet, which should be set as ActiveSheet.