?
Solved

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

Posted on 2013-01-24
4
Medium Priority
?
1,088 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 37

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 37

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

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

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

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
Suggested Courses

770 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