Consulting

Results 1 to 3 of 3

Thread: VBA To Create Slides

  1. #1

    Question VBA To Create Slides

    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

  2. #2
    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.

  3. #3
    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:

    PHP Code:
    <?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
    Last edited by Aussiebear; 04-28-2023 at 08:19 PM. Reason: Adjusted the code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •