相关文章推荐
深沉的便当  ·  GitHub | DevOps ...·  8 月前    · 
绅士的竹笋  ·  海悅聯名卡·  1 年前    · 
阳刚的烤地瓜  ·  Parsing dates in ...·  1 年前    · 
刚毅的酱牛肉  ·  java bufferedwriter ...·  2 年前    · 

This code works but I get a ton of unneeded data. Is there an easier way to go to a specified page in a Word document or a way to suppress all the unwanted info. Here I'm going to page 2:

# create a word object
$w = New-Object -ComObject Word.Application
# make it visible
$w.visible = $true
# create a document object by opening a file
$doc = $w.Documents.Open('\\servername\Users\Christian.Bahnsen\Desktop\ToDo Folder\word\splitTest\batch721extract.docx')
# create a selection object
$objSelection = $w.Selection
# parameters equate to (wdGoToPage,wdGoToAbsolute,pageNumber)
$objSelection.GoTo(1,1,2)  

This takes me to page 2 but I'm getting a ton of unwanted info in the PowerShell ISE, e.g.,

PS C:\Users\Christian.Bahnsen> $mySelection.GoTo(1,1,2)
Text                      : 
FormattedText             : System.__ComObject
Start                     : 2099
End                       : 2099
Font                      : Microsoft.Office.Interop.Word.FontClass
Duplicate                 : System.__ComObject
StoryType                 : 1
Tables                    : System.__ComObject
Words                     : System.__ComObject
Sentences                 : System.__ComObject
Characters                : System.__ComObject
Footnotes                 : System.__ComObject
Endnotes                  : System.__ComObject
Comments                  : System.__ComObject
and so forth for several pages

So is there an easier way to go to a specific page or is there a way to quash all the info posh is spitting back at me?

Thanks in advance for any assistance.

Christian Bahnsen

If you want no output you can just redirect it to null

$mySelection.GoTo(1,1,2) | Out-Null  

Best Regards,

============================================

If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.