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,017 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

18 Experts available now in Live!

Get 1:1 Help Now