Dear forum members,
I am very new to Powershell, and I am curious about the vast opportunities it can give me.
However: I have much to learn.
My 1st quest is to
- join multiple txt - files into 1 larger file
- migrate the txt - files contents to a Word file
- Run (from Powershell) several Word - macro’s
- Migrate the contents of the Word file to Excel.
I have figured out the 1st 2 steps. (thanks Google)
I have figured out how to run a Word macro (there is only 1 word file in the directory)
For 1 macro it works.
I use the code:
$Word = new-object -comobject Word.application
$WordFiles = Get-ChildItem -Path D:\PowershellTest\Dir2Twee -Include *.doc -Recurse
<# maybe the recurse can be left out since there are no subdirectories #>
Foreach($file in $WordFiles)
{
$Doc = $Word.Documents.open($file.fullname)
$workDocument = $Doc.workDocument #.item(1)
$Word.Run("Preben_01_JaarTabs")
$Doc.save()
$Doc.close()
}
$Word.quit()
This macro basically is a repeated find and replace action and works
The 2nd macro doesn’t work.
This should perform
- portait to landscape orientation
- change font
- insert tabes etc
Does this macro need a different way, or code to activate it, if it works on settings in Word?
It works perfectly fine if activated from within Word (as do all the other macro’s)
To run all 4 macro’s in 1 go I have added the same syntax as in “$Word.Run(“Preben_01_JaarTabs”)” for the others.
I have put them each on a new line, following the line …Preben_01_jaartabs
Thanks in advance for your help
Kind regards
Hein