tlc53
Active Member
- Joined
- Jul 26, 2018
- Messages
- 399
Hi there,
I have a spreadsheet with input pages and then various tabs for the respective reports. Not all report pages are required, and some are hidden (not visible) based on the users' selections on the setup page.
I have a formulated a drop-down list, which shows the reports available for saving to the system. This works fine, however, I would like an option that saves all the relevant report pages into one document - "Save All Reports". Is there a way to select and save only the visible report pages or those in the formulated drop-down list? My drop-down list is located in U1:U8 and has the following options when all reports are available.
Please Select
Save All Reports
Header Report
Cashflow Report
Milksolids Report
Stock Report
Annual Report
Analysis Report
Thank you!
I have a spreadsheet with input pages and then various tabs for the respective reports. Not all report pages are required, and some are hidden (not visible) based on the users' selections on the setup page.
I have a formulated a drop-down list, which shows the reports available for saving to the system. This works fine, however, I would like an option that saves all the relevant report pages into one document - "Save All Reports". Is there a way to select and save only the visible report pages or those in the formulated drop-down list? My drop-down list is located in U1:U8 and has the following options when all reports are available.
Please Select
Save All Reports
Header Report
Cashflow Report
Milksolids Report
Stock Report
Annual Report
Analysis Report
Thank you!
VBA Code:
'Save Report Macros
If Not Intersect(Target, Range("L4")) Is Nothing Then
Select Case Range("L4")
Case "Header Report": PDF_HEADER
Case "Cashflow Report": PDF_CASHFLOW
Case "Milksolids Report": PDF_MILKSOLIDS
Case "Stock Report": PDF_STOCK
Case "Annual Report": PDF_ANNUAL
Case "Analysis Report": PDF_ANALYSIS
End Select
End If
Code:
Sub PDF_HEADER()
Range("L4").Value = "Please Select"
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
Dim blnWasSheetHidden As Boolean
On Error GoTo errHandler
Set wbA = ActiveWorkbook
Set wsA = Sheet1
'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & ""
strName = wsA.Range("A1").Value _
& " - " & wsA.Range("A2").Value _
& " " & Format(wsA.Range("A3"), "dd.mm.yy")
'create default name for savng file
strFile = strName & ".pdf"
strPathFile = strPath & strFile
'use can enter name and
' select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strName & ".pdf", _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")
'export to PDF if a folder was selected
If myFile <> "False" Then
If wsA.Visible = xlSheetHidden Then
wsA.Visible = xlSheetVisible
blnWasSheetHidden = True
End If
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
If blnWasSheetHidden = True Then
wsA.Visible = xlSheetHidden
End If
'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
Last edited: