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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

717 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