user7898379
user7898379

Reputation: 1

PowerShell Equivalent for Word ActiveDocument.ConvertNumbersToText

I have a VB script within a Word doc macro that converts autonumber fields to text. The VB script is as follows:

Sub ReplaceNumbers() 
    ActiveDocument.ConvertNumbersToText
End Sub

How can this be launched from within PowerShell to prevent the need to run a macro within Word? I have tried several things and have been unable to get it to function correctly.

Thanks in advance.

Upvotes: 0

Views: 647

Answers (1)

Jimmy Smith
Jimmy Smith

Reputation: 2451

It's going to be a bit different as you're not actually within the context of the "ActiveDocument" so you'd have to open it via the Microsoft Word object, then run createdDocumentObject.ConvertNumbersToText. Also, you'll want to save the following to a ".VBS" here's an example to be ran when you need it.

Set objWord = CreateObject("Word.Application")
Set yourDoc = objWord.Documents.Open("c:\YourDocumentHere.doc")

yourDoc.ConvertNumbersToText
yourDoc.Save    
objWord.Quit 

Name this file something like "ConvertNumbersToTextInDocuments.vbs"

Ultimately, from Powershell then you'd need to execute this.

cscript.exe C:\ConvertNumbersToTextInDocuments.vbs

Upvotes: 1

Related Questions