BATCH Run a Word Macro

Not applicable

I would like to run a word macro (for converting files to PDF without any markup comments) for many files in a given folder

I pieced this together from other powerShell scripts I had and it doesn't work








$Files = Get-ChildItem "$FilePath\*.docx"


$Word = New-Object -ComObject Word.Application


Foreach ($File in $Files) {

# open a Word document, filename from the directory

$Doc = $Word.Documents.Open($File.FullName)


#run Macro to Export to PDF without comments






(I got the macro from MVP Doug Robbins)
[here is the macro and a link to the thread on a diffrerent Microsoft Q&A where I received this


With ActiveWindow.View.RevisionsFilter

.Markup = wdRevisionsMarkupNone

.View = wdRevisionsViewFinal

End With

With ActiveDocument

.ExportAsFixedFormat Left(.FullName, InStr(.FullName, ".") - 1), wdExportFormatPDF, True, wdExportOptimizeForPrint

End With

1 Reply

Replace with

$Word.Run and it will work fine.