Search code examples
powershellms-wordz-order

Powershell Word ZOrder


Powershell is ignoring my ZOrder commands. It doesn't matter which method I use. How can ZOrder be modified for a picture or shape added to a word document from powershell?

Method 1:

$Doc = $Word.Application.Documents.Open($docPath)
$Shape = $Doc.Shapes.AddShape(1, 0, 0, 612, 792)
$Shape.Fill.UserPicture("C:\pic.tif")
$Shape.ZOrder.msoSendToBack

Method 2:

$Doc = $Word.Application.Documents.Open($docPath)
$Shape = $Doc.Shapes.AddPicture("C:\pic.tif", $false, $true, 0, 0, 612, 792)
$Shape.ZOrder.msoSendToBack

Solution

  • ZOrder is a functional call that takes an MsoZOrderCmd. So, you need to do:

    $msoSendToBack = 1
    $Shape.ZOrder($msoSendToBack)
    

    See: https://msdn.microsoft.com/en-us/library/aa432726(v=office.12).aspx for the enum list.