![]() |
|
|
|
#1
|
||||
|
||||
|
As a VBScript, the following should be saved into a text file and given a name that ends with ".vbs". Make sure you provide a valid path to the logo up the top.
Code:
Dim sLogo, objArgs, objFSO, objWord, I
sLogo = "C:\Path\Logo.jpg" 'substitute path to your logo
Set objArgs = WScript.Arguments
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objArgs.Count = 0 then
wScript.Echo "You need to drop Word documents onto this script!"
Else
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
For I = 0 to objArgs.Count - 1
LogoAndPDF objArgs(I)
Next
objWord.Quit
End If
Function LogoAndPDF(sFilePath)
Dim sFolder, sBaseName, sExt, sPDF, oDoc, oRng
sFolder = objFSO.GetParentFolderName(sFilePath) & "\"
sBaseName = objFSO.GetBaseName(sFilePath)
sExt = objFSO.GetExtensionName(sFilePath)
sPDF = sFolder & sBaseName & ".pdf"
Select Case sExt
Case "doc", "docx", "docm"
Set oDoc = objWord.Documents.Open(sFilePath)
oDoc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True
Set oRng = oDoc.Sections(1).Headers(2).Range
oRng.Text = ""
oRng.InlineShapes.AddPicture sLogo
oRng.ParagraphFormat.Alignment = 1 'wdAlignParagraphCenter
oDoc.ExportAsFixedFormat sPDF, 17 'wdExportFormatPDF
oDoc.Close False
End Select
End Function
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#2
|
|||
|
|||
|
Andrew, Graham - you are amazing. Both scripts work beautifully.
Im speechless. This will save me hours of manual work. Thank you guys so much. I wish there was a way to repay you. (if there is, please let me know!) Thank you again Chris |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to save a PDF with header that extends to edge of page?
|
LadyJemima | Word | 4 | 03-19-2017 02:58 PM |
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 |
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 |