本文介绍了将副本另存为.PDF&.xlsx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试保存工作簿的副本,但是在保存时不知道如何设置文件类型,此代码可以创建文件,但是它们已损坏并且无法打开.
I'm trying to save copies of the workbook but don't know how to set the file type when saving, this code makes the files but they're corrupt and cannot be opened.
Sub Saves1()
'Store Answers
Dim SavePdfAnswer As String
Dim SaveXlsxAnswer As String
SavePdfAnswer = VBA_CS.Range("C2")
SaveXlsxAnswer = VBA_CS.Range("C3")
'Store File Path And Names
PdfFilePath = VBA_CS.Range("M2") & "\" & ActiveSheet.Range("F9") & ".pdf" 'File path for pdf file
ExcelFilePath = VBA_CS.Range("M2") & "\" & ActiveSheet.Range("F9") & ".xlsx" 'File path for excel xlsx file
'Save as pdf
If SavePdfAnswer = "Yes" Then
ActiveWorkbook.SaveCopyAs PdfFilePath
End If
'Save as excel xlsx
If SaveXlsxAnswer = "Yes" Then
ActiveWorkbook.SaveCopyAs ExcelFilePath
End If
End Sub
推荐答案
对于pdf:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="path\pdf_from_excel.pdf" _
, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=True, OpenAfterPublish:=True
对于xlsx:
ActiveWorkbook.SaveAs Filename:= _
"path\excel_file_name.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
希望这可以满足需要
这篇关于将副本另存为.PDF&.xlsx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!