Reputation: 2402
I need VBA to check if folder with name "Secret_information" already exists. If folder already exists then I need to save PDF and Excel from Worksheet (1) to this folder with special name (see VBA below). If folder does not exists then create new folder in the same direction my opened Excel file is already located. I have made VBA but it doesn't work correctly. Now it doesn't create xls file only pdf. Also this code creates folder to Desktop, I need it to create folder inside folder my opened Excel file is located. How to make it work?
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
Upvotes: 1
Views: 374
Reputation: 10433
\
in Application.ThisWorkbook.Path & "" & "Secret_information"
so it should be Application.ThisWorkbook.Path & "\" & "Secret_information"
ActiveWorkbook.SaveAs NewPath & "\Secret_information_" &
[Pricelist!E2] & "_" & "DD" & [Material!J8] & "_" & Date
it should be ActiveWorkbook.SaveAs NewPath & "\Secret_information_" & [Pricelist!E2] & "_" & "DD" & [Material!J8] & "_" & Format(Date,"ddmmmyy" )& ".xls",xlExcel8
Add the file format for xls as xlExcel8
Upvotes: 1