gpt4 book ai didi

VBA 另存为 PDF,文件名作为单元格值

转载 作者:行者123 更新时间:2023-12-02 04:17:42 25 4
gpt4 key购买 nike

我正在尝试将四张纸保存到一个 PDF 中。下面的代码是我到目前为止所拥有的。当我在文件名中使用 ActiveSheet.Name 命令时,它可以工作,但是当我将其更改为动态单元格的范围时,它不再工作并出错。任何帮助将不胜感激。

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,文件名作为单元格值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26350314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com