VBA Save as PDF with file name as cell value

I am trying to save four sheets in one pdf file. The code below is what I still have. When I use the ActiveSheet.Name command in a file name, it works, however, when I change it to a range for a dynamic cell, it no longer works and there are no errors. Any help would be appreciated.

Sheets(Array("Dashboard Pg 1", "Dashboard Pg 2", "Dashboard Pg 3", _ "Dashboard Pg 4")).Select Sheets("Dashboard Pg 1").Activate ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ "C:\Users\Allen\Desktop\Projects\" & ActiveSheet.Range("K17").Value & ".pdf" _ , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _ :=False, OpenAfterPublish:=False Sheets("Summary").Select 
+6
source share
1 answer

Try the following:

 Dim strFilename As String Dim rngRange As Range 'Considering Sheet1 to be where you need to pick file name Set rngRange = Worksheets("Sheet1").Range("K17") 'Create File name with dateStamp strFilename = rngRange.Value & Format(Now(), "yyyymmdd hhmmss") Sheets(Array("Dashboard Pg 1", "Dashboard Pg 2", "Dashboard Pg 3", "Dashboard Pg 4")).Select Sheets("Dashboard Pg 1").Activate ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ "C:\Users\Allen\Desktop\Projects\" & strFilename & ".pdf" _ , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _ :=False, OpenAfterPublish:=False Sheets("Summary").Select 
+9
source

Source: https://habr.com/ru/post/976693/


All Articles