我需要VBA检查名称为“ Secret_information”的文件夹是否已经存在。如果文件夹已经存在,则需要使用特殊名称将Worksheet(1)中的PDF和Excel保存到该文件夹(请参见下面的VBA)。如果文件夹不存在,则以相同的方向创建新文件夹,而我打开的Excel文件已经位于该文件夹中。我已经制作了VBA,但无法正常工作。现在,它不会仅创建xls文件pdf。这段代码也创建了到Desktop的文件夹,我需要它在打开的Excel文件所在的文件夹内创建文件夹。如何使其运作?
Sub CommercialPart()
Dim NewPath As String
NewPath = Application.ThisWorkbook.Path & "" & "Secret_information"
If Dir(NewPath, 63) = "" Then MkDir NewPath
ActiveWorkbook.Sheets(1).Select
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=NewPath & "\Secret_information_" & [Pricelist!E2] & "_" & "SC" & [Technical!I11] & "_" & Date & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=No, _
OpenAfterPublish:=False
ActiveWorkbook.Sheets(1).Copy
ActiveWorkbook.SaveAs NewPath & "\Secret_information_" & [Pricelist!E2] & "_" & "DD" & [Material!J8] & "_" & Date
ActiveWorkbook.Close
End Sub
\
,Application.ThisWorkbook.Path & "" & "Secret_information"
所以应该Application.ThisWorkbook.Path & "\" & "Secret_information"
ActiveWorkbook.SaveAs NewPath & "\Secret_information_" & [Pricelist!E2] & "_" & "DD" & [Material!J8] & "_" & Date
应该是ActiveWorkbook.SaveAs NewPath & "\Secret_information_" & [Pricelist!E2] & "_" & "DD" & [Material!J8] & "_" & Format(Date,"ddmmmyy" )& ".xls",xlExcel8
将xls的文件格式添加为 xlExcel8
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句