PDA

View Full Version : VBA To Create Slides



tmptplayer
01-04-2008, 07:43 PM
Hey All,
I have some experience with VBA, but have never used Power Point's object model. My end goal is to build a power point based on an XML file. I figure I can get to the XML file through the MSXML libraries, but I'm not entirely sure how to put the data into a slide. Can anyone give me a jump start with regards how I can write text to a power point slide? Furthermore, do you know if it is possible for ppt to accept html encoded text (and format it accordingly) on the slide? Thanks!

-Brian

PS- This is for PPT 2003

tmptplayer
01-05-2008, 10:37 AM
Ok, I found some help on a knowledge base article on this site, but I can't post the link because I haven't posted enough on this site. I'll see if I can solve my problem and then post a good solution for anyone who cares.

tmptplayer
01-05-2008, 03:44 PM
Here is a power point macro that will create a slide from data in an XML file. Save the XML file (the second code segment) and adjust the file path/name variables for this file as necessary. You also need to include the MSXML v4.0 library (goto Tools->References in the VB editor).

Here is the subroutine:

Sub createPPT()
Dim xmlFileName As String
Dim fileDirectory As String
Dim strMET As String
Dim pre As Presentation
Dim sld As Slide
Dim xmlNode As IXMLDOMNode
Dim METAR As IXMLDOMNode
Dim xDoc As New MSXML2.DOMDocument40
fileDirectory = "C:\Documents and Settings\HP_Administrator\My Documents\"
xmlFileName = "wxBriefInfo.xml"
xDoc.Load (fileDirectory & xmlFileName)
Set METAR = xDoc.selectSingleNode("//KMEI/TAF")
strMET = METAR.Text
Set pre = ActivePresentation()
Set sld = pre.Slides.Add(pre.Slides.Count + 1, ppLayoutText)
sld.Shapes(2).TextFrame.TextRange = strMET
End Sub
Here is the XML file:


<?xml version="1.0" encoding="utf-8"?>
<stations>
<KMEI>
<METAR> Weather Report Here </METAR>
<TAF> Weather Forecast Here </TAF>
</KMEI>
</stations>

Finally- I got this far thanks to DRJ's knowledge base article: http://vbaexpress.com/kb/getarticle.php?kb_id=177