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,061 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SuperAntiSpyware Licenses Discounted by 25% !

Exclusive offer to Experts Exchange Members!
Buy SuperAntiSpyware License(s) from us and save 25% on the regular purchase price.
- Includes Full SuperAntiSpyware Vendor Support Entitlements
- Your Subscription does not begin until you activate your license
- Buy for your friends

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
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 …

738 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