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
• 27,740 points
40 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
• 51,240 points

Related Questions In Others

0 votes
1 answer
0 votes
1 answer
0 votes
0 answers
0 votes
1 answer

Excel VBA : HOW TO PRINT THE TEXT IN A CELL (like Wrap Text)

Use a LineFeed character to create a ...READ MORE

answered Oct 27, 2022 in Others by narikkadan
• 51,240 points
172 views
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
• 51,240 points
66 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
• 27,740 points
68 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
• 51,240 points
33 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
• 51,240 points
43 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