Setting the position of guidelines in PowerPoint from a VBA script

As I had to find out today, you cannot set the position of guidelines in PowerPoint from a VBA macro. But if you need a set of accurately positioned guidelines like shown in the screenshot below (exactly 32 vertical guidelines with the same distance between them), it would be almost impossible to position them by hand.

Accurately positioned PowerPoint guidelines

However, as you may know, PowerPoint’s PPTX files are simply zipped XML files, that can be extracted, analyzed (e.g. diffed), and modified. So I did exactly that and found out that the presentation’s guidelines are defined in ppt\viewProps.xml.

PowerPoint viewProps.xml

Having placed a single vertical guideline at both ends of the slide in an empty presentation, the corresponding part in viewProps.xml looks like this:

<p:guideLst> <p:guide orient="horz" pos="2160"/> <p:guide /> <p:guide pos="5760"/> </p:guideLst>

So, the rightmost position of a guideline in PowerPoint’s internal unit of measurement (whatever that is) is 5760. Now you can divide this number by the number of guidelines you would like to have (32 in my case) and add new lines to the XML file accordingly:

<p:guideLst> <p:guide orient="horz" pos="2160"/> <p:guide /> <p:guide pos="180"/> <p:guide pos="360"/> ... <p:guide pos="5760"/> </p:guideLst>

Now you can zip up the folder again, rename the file to pptx and open it in PowerPoint.

As the title of this blog post suggests, the above process could be automated. However, as zip file handling is not built in into PowerShell at the moment, I leave this exercise for the reader 😉

Über Stefan

Polyglot Clean Code Developer

Ein Kommentar

  1. Actually the measurements are eighths of a point and the default slide width is 10 inches. So 10 inches is 10 * 72 = 720 points. 720 points * 8 = 5760. I have no idea why this measurement was used over the other weird ones out there.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax