VBA Export as PDF and Save to Location with name as per a Cell in the worksheet

0 votes
It will save under the name I give it, which is acceptable, and I recorded a macro to export as a PDF.

The subsequent save, however, overwrite the initial save.

I configured Cell "S2" to show the file location, file name, and the current date and time.

How can I export using cell S2 as the location and filename in VBA?
Jan 20 in Others by Kithuzzz
• 38,010 points
1,167 views

1 answer to this question.

0 votes

Following is the code that gets generated when you record a macro to export excel to pdf.

Recorded Code :

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "C:\users\Desktop\macros\filename.pdf", Quality _
    :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=True

Update Code to get the filename from cell S2:

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    **Range("S2").Value** & ".pdf", Quality _
    :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=True
answered Jan 20 by narikkadan
• 63,180 points

Related Questions In Others

0 votes
1 answer
0 votes
1 answer
–1 vote
0 answers
0 votes
1 answer

Can a worksheet ActiveX ComboBox work on a Mac?

ActiveX is an outdated Windows technology that ...READ MORE

answered Nov 17, 2022 in Others by narikkadan
• 63,180 points
343 views
0 votes
0 answers

Strikethrough in Excel VBA

When I enter the second date in ...READ MORE

Nov 27, 2022 in Others by Kithuzzz
• 38,010 points
271 views
0 votes
1 answer

Excel VBA- Creation of a New datablock with criteria

To insert the dropdown, you can go ...READ MORE

answered Jan 12 in Others by narikkadan
• 63,180 points
172 views
0 votes
1 answer

I want to compare two Excel files and highlight the differences with VBA

The workbook doesn't have the UsedRange property ...READ MORE

answered Jan 13 in Others by narikkadan
• 63,180 points
1,532 views
0 votes
1 answer

Create a hyperlink to a sheet with same name as the value in the selected cell in Excel through VBA

Credit to Spectral Instance who found the ...READ MORE

answered Feb 6 in Others by narikkadan
• 63,180 points
380 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP