I have a PowerShell script that collects data from Active Directory and puts it into a nicely formatted Word Document and appends the date at the end of the file name when it is saved so I can see the different files and when they were ran.
I then run the Document Merge in Word to save the file with the differences indicated between the last two times the script ran.
***I want to automate this process.***
I don't want a third party application to do this. I want to be able to do this with either PowerShell or VBS or a VBS called out from with in a PowerShell Script.
PowershellVB ScriptActive DirectoryMicrosoft Word
Last Comment
Pber
8/22/2022 - Mon
GrahamSkan
This is VBA code for the basic merge function. It can be called from the command line or converted to VBS.
Dim wdApp As Word.Application Dim wdDoc As Word.Document Dim docMain As Word.Document Dim bNewInstance As Boolean Dim strMainDoc As String strMainDoc = "C:\MyFolder\MyMainMerge.docx" 'Try to use already running instance of Word On Error Resume Next Set wdApp = GetObject(, "Word.Application") On Error GoTo 0 If wdApp Is Nothing Then 'there wasn't one, so create a new one Set wdApp = CreateObject("Word.Application") bNewInstance = True End If Set docMain = wdApp.Documents.Open(strMainDoc) docMain.MailMerge.Execute docMain.Close wdDoNotSaveChanges 'leave application open in case there is a result document to be saved 'otherwise 'only close Word application if instance created for this macro If bNewInstance Then wdApp.Quit End If
No, I wrote that from scratch, though it's adapted from some of my library code. If it were recorded, you would see the Selection object, method or both. Does it matter?
If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.
Open in new window