Macro- save as PDF to folder

mtravis38

Board Regular
Joined
Apr 13, 2010
Messages
61
Good morning,

I have a macro (see below), part of which saves the Excel file to PDF and names the file. Unfortunately, it also saves the file to a destination folder, and I'm not sure why.

What I would like to do is save the PDF to the same folder as the Excel file from which the PDF was created. This file location will not always be the same, so I can't just insert a specific file path. Any help would be appreciated.

The bolded part of the macro saves the file. Even though the file path is not explicitly stated, it always saves to my "W" drive.

Also note that none of the "called" macros have anything to do with the file save.

Sub Approval_xxxx()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
'<o:p></o:p>
' Approval_xxxx Macro<o:p></o:p>
'<o:p></o:p>
ActiveSheet.Unprotect<o:p></o:p>
Application.ScreenUpdating = False<o:p></o:p>
Dim MyPassword<o:p></o:p>
MyPassword = InputBox("Please enter password", "Password Prompt", "********")<o:p></o:p>
If MyPassword = "xxxx" Then<o:p></o:p>
MsgBox "Access Granted", vbInformation, "Access"<o:p></o:p>
Dim objSheet As Worksheet<o:p></o:p>
Range("V8").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "=TODAY()"<o:p></o:p>
Range("V8").Select<o:p></o:p>
Selection.Copy<o:p></o:p>
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _<o:p></o:p>
:=False, Transpose:=False<o:p></o:p>
Range("E39").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "xxxx"<o:p></o:p>
ActiveSheet.Protect DrawingObjects:=False<o:p></o:p>
Call JOC_Sig<o:p></o:p>
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("a48").Text, Quality:=xlQualityStandard, _<o:p></o:p>
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _<o:p></o:p>
True<o:p></o:p>
Worksheets("A-1 COVER").Select<o:p></o:p>
Range("D6").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "xxxx"<o:p></o:p>
Range("F6").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "R"<o:p></o:p>
Range("M6").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "=TODAY()"<o:p></o:p>
Range("m6").Select<o:p></o:p>
Selection.Copy<o:p></o:p>
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _<o:p></o:p>
:=False, Transpose:=False<o:p></o:p>
Range("M7").Select<o:p></o:p>
ActiveWindow.SmallScroll Down:=39<o:p></o:p>
Range("F58").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "=TODAY()"<o:p></o:p>
Range("f58").Select<o:p></o:p>
Selection.Copy<o:p></o:p>
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _<o:p></o:p>
:=False, Transpose:=False<o:p></o:p>
Range("J58").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "xxx"<o:p></o:p>
Range("K59").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "R"<o:p></o:p>
Range("M59").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "xxx"<o:p></o:p>
Range("F62").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "R"<o:p></o:p>
Call Hide_Blank_Comments<o:p></o:p>
Range("B78").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "xxxx"<o:p></o:p>
Else<o:p></o:p>
MsgBox "Access denied", vbCritical, "Error"<o:p></o:p>
Exit Sub<o:p></o:p>
End If<o:p></o:p>
Application.ScreenUpdating = True<o:p></o:p>
End Sub<o:p></o:p>
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try:

Code:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=[B][COLOR=red]ActiveWorkbook.Path & Application.PathSeparator &[/COLOR][/B] Range("a48").Text, Quality:=xlQualityStandard, _<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _<o:p></o:p>
True<o:p></o:p>
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,687
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top