Automatically Generating Reports: Word and PDF Output from Excel
Automate document creation for consistent reporting.
Export a sheet or range to PDF
Sub ExportPdf() Dim p As String p = ThisWorkbook.Path & Application.PathSeparator & "Report.pdf" Worksheets("Report").ExportAsFixedFormat xlTypePDF, p End Sub
Mail merge with Word (late bound)
Sub CreateWordDoc() Dim wd As Object: Set wd = CreateObject("Word.Application") Dim doc As Object: Set doc = wd.Documents.Add wd.Visible = True doc.Content.InsertAfter "Hello from Excel" doc.SaveAs2 ThisWorkbook.Path & "\Hello.docx" End Sub
Work faster with the VBA Assistant
Create, explain, and improve your VBA code with examples, comments, and best practices—directly in your workflow.
