ITguy565
asked on
Powershell Scripting : Merge Visio Document into word Document using nothing but powershell.
Experts,
I have a need to insert a visio document into a word document programmatically what is the easiest way to do this?
A snippet of my code is as follows:
I Thought I might be able to do the following, but it fails with
Word has encountered a problem.
At line:1 char:1
+ $selection.InsertFile("C:\ worddoc\wo rdmerge\Dr awingvsdx. vsdx")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServ ices.COMEx ception
I have a need to insert a visio document into a word document programmatically what is the easiest way to do this?
A snippet of my code is as follows:
#Create word Instance
$merged_Object = ""|TitleHeadingBar
$Merged_Object.TitleheadingBar = "Test"
$Word = New-Object -ComObject Word.Application
#Make Word Visible
$Word.Visible = $True
#Create Blank Document
$Document = $Word.Documents.Add()
#Create Selection object
$Selection = $Word.Selection
#Alignment Options:
$Alignment = ""|Select Center,Left,Right
$Alignment.Center = "1"
$Alignment.Left = "0"
$Alignment.Right = "2"
#Create Content
$Selection.ParagraphFormat.Alignment = "$($Alignment.Center)"
$Selection.Font.Bold = 1
$Selection.Font.Italic = 1
$Selection.Font.Underline = 1
$selection.TypeText("$($Merged_Object.TitleHeadingBar))")
I Thought I might be able to do the following, but it fails with
$selection.InsertFile("C:\worddoc\wordmerge\Drawingvsdx.vsdx")
Word has encountered a problem.
At line:1 char:1
+ $selection.InsertFile("C:\
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServ
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
here was the answer I arrived at: