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, 2023 in Others by Kithuzzz
• 38,000 points
1,918 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, 2023 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

VBA code help - Add a line for each missing date with the start and end date defined in a cell

Try this: Sub FillDates() Dim ...READ MORE

answered Jan 24, 2023 in Others by narikkadan
• 63,600 points
989 views
0 votes
1 answer
–2 votes
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,600 points
616 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,000 points
512 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, 2023 in Others by narikkadan
• 63,600 points
466 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, 2023 in Others by narikkadan
• 63,600 points
2,576 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, 2023 in Others by narikkadan
• 63,600 points
911 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