I have a macro to save a worksheet and protect it. It then also saves the new worksheet as a PDF. I want to save the PDF into a particular subfolder called "Invoices" The sub folder will always be in the main folder. I cant use a spefic path at the main folder needs to work on different computers. this is what I have so far.
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub AddSheet()[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Dim ws As Worksheet
Dim wh As Worksheet
Set ws = Worksheets(ActiveSheet.Name)
ActiveSheet.Copy After:=Worksheets(Sheets.Count)
Set wh = Worksheets(Sheets.Count)
If ws.Range("e9").Value <> "" Then
wh.Name = ws.Range("E9").Value
ActiveSheet.Protect
End If
wh.Activate
Range("A1").Select
ChDir ActiveWorkbook \ Invoices
[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("E9")
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("E9"), _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif][/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif] End Sub
[/FONT]
It all works except for the location of the PDF file. If I remover the following line
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub AddSheet()[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Dim ws As Worksheet
Dim wh As Worksheet
Set ws = Worksheets(ActiveSheet.Name)
ActiveSheet.Copy After:=Worksheets(Sheets.Count)
Set wh = Worksheets(Sheets.Count)
If ws.Range("e9").Value <> "" Then
wh.Name = ws.Range("E9").Value
ActiveSheet.Protect
End If
wh.Activate
Range("A1").Select
ChDir ActiveWorkbook \ Invoices
[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("E9")
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("E9"), _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif][/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif] End Sub
[/FONT]
It all works except for the location of the PDF file. If I remover the following line
ChDir ActiveWorkbook \ Invoices
it saves in the same folder as the excel file. But I want it into a subfolder called Invoices which is located in the same folder.
it saves in the same folder as the excel file. But I want it into a subfolder called Invoices which is located in the same folder.