Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #---Useless initialization stuff----------------------
- $date = get-date -format MM-dd-yyyy-HH-mm-ss
- #$filePath = "C:\Users\Tomawar40\TestDocStore"
- [ref]$SaveFormat = "microsoft.office.interop.word.WdSaveFormat" -as [type]
- $word = New-Object -ComObject word.application
- $word.visible = $true
- $doc = $word.documents.add()
- $selection = $word.selection
- #---USELESS - $selection.WholeStory
- $selection.Style= "No Spacing"
- $selection.font.size = 12
- $selection.font.bold = 1
- $selection.typeText("My Document: THIS IS A TEST TITLE")
- #---Previous Parts Are to set up and initially make a first line on the Document.
- $selection.font.size = 10
- $selection.font.bold = 0
- #---------- Here's where the trouble starts--------------
- #$selection.typeText("`v")
- #$selection.typeText("=lorem(9,10)`v")
- # ***Begin new
- $selection.TypeParagraph()
- [void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
- [void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
- $app = Get-Process winword
- '=lorem(9,10)' | clip
- [Microsoft.VisualBasic.Interaction]::AppActivate($app.ID)
- $selection.Paste()
- Start-Sleep 1
- $selection.TypeParagraph()
- $selection.MoveLeft()
- [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
- # ***End New
- #--FAILED TEST A: Test to maybe press enter?
- #--FAILED TEST B: Add-Type -AssemblyName System.Windows.Forms
- #-- [System.Windows.Forms.SendKeys]::SendWait('~');
- #--FAILED TEST C: $selection.sendKeys({ENTER})
- sleep 5
- $selection.TypeParagraph()
- $selection.TypeParagraph()
- $Selection.font.size = 11
- $selection.typeText("Date: $date")
- #---This part saves the document and then closes the word application
- $doc.saveas([ref] $filePath, [ref]$saveFormat::wdFormatDocument)
- $doc.Close()
- $word.Quit()
- #---This part clears up memory and destroys the instance
- $null = [System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$word)
- [gc]::Collect()
- [gc]::WaitForPendingFinalizers()
- Remove-Variable word
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement