Excel VBA Macro: Save Selected Range as PDF (and Center on Page)

Excel VBA Macro: Save Selected Range as PDF (and Center on Page). In this video, we go over how to write code that allows us to select a range on a worksheet and only use that selected range to create a pdf, save the pdf, and align the range in the center of the page. We also go over how to include icons from excel in our new pdf.
Code:
Sub save_range_as_pdf()
Dim pdf_range As Range
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
Set pdf_range = ws.Range("B2:C14")
ws.PageSetup.CenterHorizontally = True
pdf_range.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\Users\greggowaffles\Documents\" & _
"KZread Videos\Test\Cookie Sales Reports\" & _
"Cookie Sales Report " & _
ws.Range("B11").Text & ".pdf", OpenAfterPublish:=True
End Sub
#ExcelVBA #ExcelMacro

Пікірлер: 11

  • @drewgossage8842
    @drewgossage88422 жыл бұрын

    Another great update!! Your style is just like someone casually showing you how to do something at work. Casual, yet really informative 👍👍

  • @greggowaffles

    @greggowaffles

    2 жыл бұрын

    That’s the goal! I really appreciate the feedback!! Thank you 🙏

  • @Master-bx4rd
    @Master-bx4rd11 ай бұрын

    Hi, Presented excercise looks very good. But I wanted to export a range e.g. A1:R50 into 1 pdf page only. I'm trying to do it, but it still expotrs to the 2 pages which is what I don't want to. Any help apreciated Regards

  • @selvan1264
    @selvan1264 Жыл бұрын

    Excellent video!!! May I check how to use excel VBA to save as secured pdf? The pdf will not be editable, cannot copy paste only for read only etc...Thank you

  • @MuntasirSaqif
    @MuntasirSaqif Жыл бұрын

    Thanks Greg , learned a lot by watching your videos. Quick question: I have a table of data and when saving the data to PDF, the PDF is displaying my table in multiple pages. For example, the category in one page and the corresponding sales in another. How can I fix this? Thanks

  • @MrHatem55
    @MrHatem552 жыл бұрын

    Hi thank you. Your videos helped me a lot at work Could you please do a video about how to get all updated documents from files? I have a file called “weekly report “ I want to gather only the updated documents 3 excel file and 1 word from different files to my main folder “Weekly report” is that doable? Thanks in advance 🙏🏽

  • @greggowaffles

    @greggowaffles

    2 жыл бұрын

    Glad to hear that! I think so. So you want a macro that looks through certain folders and grabs the most updated documents in each folder to put in another folder?

  • @MrHatem55

    @MrHatem55

    2 жыл бұрын

    @@greggowaffles Yes exactly. Plus it would be great if I can do the file can update it self weekly without me doing anything

  • @greggowaffles

    @greggowaffles

    2 жыл бұрын

    ok cool. I’ll make a video on that and I’ll probably spread it across two videos to incorporate the second part

  • @MrHatem55

    @MrHatem55

    2 жыл бұрын

    @@greggowaffles Thank you 🙏 ♥️ Waiting for your magic 🪄

  • @greggowaffles

    @greggowaffles

    2 жыл бұрын

    🪄Excel VBA Macro: Open Newest Files (from Multiple Folders) and Save Them in Another Folder kzread.info/dash/bejne/k213vNtrqNidabA.html