View all posts filed under 'Office 2007'

Small PowerShell function library for Word2007

Thursday, 6. August 2009 20:59

I created a small library of functions for creating word documents using PowerShell. The library contains 8 functions that allow you to create simple documents in Word2007 (maybe also Word 2003 but I haven’t been able to test it yet).

The functions are:

  1. WORD\Invoke-Word
  2. WORD\Add-Heading
  3. WORD\Add-Paragraph
  4. WORD\Add-Table
  5. WORD\Add-TableOfContents
  6. WORD\Add-PageBreak
  7. WORD\Add-TextBox
  8. WORD\Update-TablesOfContents

A small example script is included in the zip file which can be downloaded here.

A screenshot of one of the chapter generated by the example script:

 

word

Category:Office 2007, PowerShell | Comment (0) | Author: Dennis Damen

Issues with PowerShell 2 CTP(v3) and Word2007

Thursday, 6. August 2009 10:43

At Login Consultants I’m using a simple script to automatically document our scripting framework. After some reports of my colleagues about this script not working on Windows 7 I decided to start testing. Here’s what I found:

 

PowerShell v1.0:

posh1

 

PowerShell CTP 2.0 (V3):

posh2

Anyone got some idea what is going on?

Category:Gotcha, Office 2007, PowerShell | Comment (0) | Author: Dennis Damen

Powershelling Word 2007 Part 1

Monday, 23. February 2009 19:26

At Login Consultants we have created a rather extensive scripting framework based on PowerShell scripts called Solution4. Conceptually it is similar to an earlier version of Solution4 which was based on CMD scripting and a collection of tools. The power of PowerShell, however, allowed us to improve this scripting framework even beyond our own dreams.

One of the key features of this scripting framework is that we standardize the automation and even more important, the way HOW automation is performed. This extensive standardization allows us to automatically document anything we do within this scripting framework. For our documentation efforts we chose Microsoft Word 2007 because it is, or will be, the most widely used word processor and because the COM interface is relatively straightforward.

The code snippets I will post in these series about PowerShelling Word 2007 are the functions I created to create items like paragraphs, tables and headings. At the end of these series I will put the complete script online for download.

First of all, lets get Word 2007 to run from PowerShell. Word 2007 exposes its methods through a COM interface. Starting an instance of Word 2007 in PowerShell is done like this:

$msWord = new-object -com Word.Application
$msWord.Visible = $true

This first line of code will start Word 2007 but it will be invisible to you. The second line will instruct Word 2007 to materialize. While this is already pretty cool, as you can see there’s no document. The next step is to open a new document like so:

$doc = $msword.documents.add()

The document created is based on the default template. If you want to base you new document on a different template, just tell Word. See:

$doc = $msword.documents.add(“D:\GenDoc\gendoc.dotx”)

Next time I will show you how to actually add some text.

Category:Office 2007, PowerShell | Comments (2) | Author: Dennis Damen