View Single Post
 
Old 11-18-2019, 01:01 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
To run the script in Windows File Explorer, drag one or more Word documents onto the file. It will create PDFs in the same folder as the source documents.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote