Solved

PowerShell Word 2007/2010/2013 Add a Caption to Table and Move Table 3 Tabs to Right

Posted on 2013-01-24
4
1,039 Views
Last Modified: 2013-02-12
PowerShell V2
Word 2007/2010/2013

I have created a test script the inserts a Word table and populates it with no issues.

There are two more things I would like to do:

Add a caption above the table that says "Table x Citrix Services"
Move the table to the right three tab stops.

I have attached a TXT version of my test script and sample Word doc.
tabletest.txt
EESample.docx
0
Comment
Question by:Carl Webster
  • 2
4 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38865595
You might have difficult in finding a Powershell expert who also understands the Word object model.

Also, in Word, a tab stop is a property of a paragraph, and a table is not a part of a paragraph, though it can contain paragraphs, so three tab stops is not meaningful.

Try this as a Word VBA macro. If it works, I don't think it should be too difficult for a Powershell programmer to translate it.
Sub AddCaption()
    Dim tbl As Table
    Set tbl = ActiveDocument.Tables(1)
    CaptionLabels.Add Name:="Table x Citrix Services"
    With tbl
        .Range.InsertCaption Label:="Table x Citrix Services", TitleAutoText:="InsertCaption2", _
            Title:="", Position:=wdCaptionPositionAbove, ExcludeLabel:=0
        .Rows.HorizontalPosition = CentimetersToPoints(3)
    End With
End Sub

Open in new window

E
0
 
LVL 36

Accepted Solution

by:
Carl Webster earned 0 total points
ID: 38865624
A friend just figured it out for me:

$Table.Rows.SetLeftIndent(75,1)

“Use rows.setleftindent() to indent the table to your desired position. The first argument is the indent distance the second define the rulerstyle. "

He had me add it after my last ForEach loop and move the AutoFitBehaviour from where I had it to after the SetLeftIndent.

He originally had me use 200,1 but 75,1 made the table line up with the rest of my document text of three tab stops.

Works like a charm.

I decided I really didn't need a caption but that code is:

$Selection.InsertCaption(-2, " Citrix Services")

He said the -2 means the caption is for a table.

Thanks
0
 
LVL 36

Author Closing Comment

by:Carl Webster
ID: 38879516
A friend figured it out for me and his solution works perfectly for my document I am creating.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now