Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 11-18-2019, 02:53 PM
chrisx0x chrisx0x is offline VBA Script - Add Header - Save as PDF Windows 10 VBA Script - Add Header - Save as PDF Office 2019
Novice
VBA Script - Add Header - Save as PDF
 
Join Date: Nov 2019
Posts: 5
chrisx0x is on a distinguished road
Default

Graham - Just made a small donation through your website. Thanks v much.

Andrew - Let me know how I can donate.


Quote:
Originally Posted by gmayor View Post
The following should work. Open a document in Word and run the macro Installing Macros

Don't forget to change the path in the macro to the location where the logo is saved.

The process assumes that the logo is in the centre of the first page header.

Code:
Sub LogoAndPDF()

'Graham Mayor - https://www.gmayor.com - Last updated - 18 Nov 2019
Dim oHeader As Range
Dim strDocName As String
Dim intPos As Integer
Const strLogo As String = "C:\Path\Logo.jpg"    'substitute path of logo
Start:
    strDocName = ActiveDocument.FullName
    intPos = InStrRev(strDocName, ".")
    If intPos = 0 Then
        ActiveDocument.Save
        GoTo Start
    End If
    strDocName = Left(strDocName, intPos - 1)
    ActiveDocument.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True
    Set oHeader = ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
    oHeader.End = oHeader.End - 1
    oHeader.InlineShapes.AddPicture FileName:=strLogo
    oHeader.ParagraphFormat.Alignment = wdAlignParagraphCenter

    ActiveDocument.ExportAsFixedFormat OutputFilename:=strDocName, _
                                       ExportFormat:=wdExportFormatPDF, _
                                       OpenAfterExport:=False, _
                                       OptimizeFor:=wdExportOptimizeForPrint, _
                                       Range:=wdExportAllDocument, from:=1, to:=1, _
                                       Item:=wdExportDocumentContent, _
                                       IncludeDocProps:=True, _
                                       KeepIRM:=True, _
                                       CreateBookmarks:=wdExportCreateHeadingBookmarks, _
                                       DocStructureTags:=True, _
                                       BitmapMissingFonts:=True, _
                                       UseISO19005_1:=False
    ActiveDocument.Close SaveChanges:=False
lbl_Exit:
    Set oHeader = Nothing
    Exit Sub
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Script - Add Header - Save as PDF How to save a PDF with header that extends to edge of page? LadyJemima Word 4 03-19-2017 02:58 PM
VBA Script - Add Header - Save as PDF Export Access report as pdf -- save as .rft -- and Word puts some text into the header louiseword Word 1 11-21-2016 04:32 PM
VBA Script - Add Header - Save as PDF Format of Header changing after save and close shen_27 Word 4 03-19-2013 11:41 AM
How to save the current page in a new file with all the page settings (header, footer Jamal NUMAN Word 6 03-15-2012 03:27 PM
VBA Save as header page name devcon Excel Programming 0 11-25-2011 12:02 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:39 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft