本文介绍了VBA另存为PDF,文件名为单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将四张纸保存为一个PDF.到目前为止,下面的代码是我所拥有的.当我在文件名中使用ActiveSheet.Name命令时,它将起作用,但是,当我将其更改为动态单元格的范围时,它将不再起作用,并且会出错.任何帮助将不胜感激.
I am trying to save four sheets into a single PDF. The code below is what I have so far. When I use the ActiveSheet.Name command in the file name it works, however when I change it to a range for a cell that is dynamic it no longer works and errors out. 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
推荐答案
尝试一下:
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
这篇关于VBA另存为PDF,文件名为单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!