![](/img/trans.png)
[英]VBA Export as PDF and Save to Location with name as per a Cell in the worksheet
[英]Can I name an CSV export with a range/cell number from the original worksheet and also save a PDF version?
我一直在創建報價和訂單電子表格。 我一直在測試 VBA 以簡化用戶的選項,但是我發現很難使用訂單號和客戶名稱自動命名導出 CSV 和 PDF 文件。 我有 VBA 可以用於 PDF 選項,但不能用於 CSV。 訂單號在單元格“O14”中,客戶名稱在“N14”中。
我試過的代碼是:
Sub CopyCells()
' export Macro
Range("G8:O60").Select
Selection.Copy
Workbooks.Add
ActiveWorkbook.SaveAs Filename:= _
"C:Users\Desktop\Invoices\Book2.csv" _
, FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
'Create and assign variables
Dim saveLocation As String
saveLocation = "C:Users\Desktop\pdf\myPDFFile.pdf" _
'Save Active Sheet(s) as PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=Range("N14").Value & "_" & Range("O14").Value
Filename := "C:Users\Desktop\pdf\" & _
Range("N14").Value & "_" & Range("O14").Value & ".pdf"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.