Recorded Macro wont paste a cell and save file name

Adski989

New Member
Joined
Sep 13, 2017
Messages
2
Hi all,

as above, when i record the macro I copy a specific cell to be the file name, e.g customer name to enable each time i run the macro the excel sheet to be saved as a different named PDF, unfortunately the macro just takes the first file saved name and stores it to be used each time I run the macro... any pointers please?

Sub Macro5()
'
' Macro5 Macro
'


'
Range("B6").Select
Selection.Copy
ChDir "C:\Users\adam.galilee\Desktop\Quotations"
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\Desktop\Quotations\Bob 1.pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Application.CutCopyMode = False
Range("I1").Select
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Assuming B6 contains, for example, "Bob 1.pdf" then it's simply something like this:

Code:
Sub Macro5()

Dim saveFileName As String

saveFileName = Environ("USERPROFILE") & "\Desktop\Quotations\" & Range("B6").Value
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

End Sub

WBD
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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