I’m trying to convert the VBA code from the following articles into PowerShell. Everything seems to work fine apart from the setting of the placeholder text.
Viewing the default placeholdertext is easy enough ;-
$objCC.PlaceholderText.Value Choose an item.
This is my shortened code purely trying to set the placeholder text.
$Word = New-Object -Com Word.Application $template = "template.docx" #this can be any old word doc [saved in %TEMP% with a "Section4" bookmark defined] $Doc = $Word.Documents.Open($env:temp + "\" + $template) $Doc.Activate() $objRange = $Doc.BookMarks.Item("Section4").Range $objCC = $objRange.ContentControls.Add(4) # 4 = Drop down list $text = "Select upgrade type..." $objCC.SetPlaceholderText($null,$null,$text)
Get Member reveals its an available method ;-
Name MemberType Definition
SetPlaceholderText Method void SetPlaceholderText (BuildingBlock, Ra…
No matter how I try to set it fails with the following ;-
Exception calling “SetPlaceholderText” with “3” argument(s): “Type mismatch.
(Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))”
At line:1 char:1
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException + FullyQualifiedErrorId : ComMethodTargetInvocation
Can anyone throw any light on why this isnt working and how it can be done.