Consulting

Results 1 to 6 of 6

Thread: newbie help

  1. #1
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location

    newbie help

    Hi all,
    I am looking for help getting started with ppt coding.
    I am moderately competent with Excel vba, but am still trying to get my head around the ppt object models - I apologise if my questions seem rather basic.

    I am using ppt 2007, and have access to ppt 2003 (to steal code from the macro recorder)

    I have written some code to replace a text string and add some hyperlinks to a particular textbox on a particular slide - this appears to work ok

    The problem:
    I want to run this from a command button - but can only get the click event to work in presentation mode. The code then fails (presumably) because it references the slide through the 'activewindow' object.

    How can I create an easy to use mechanism to run a macro from the slide builder view (to automate the customisation of a presentation template)?

    Thanks in advance
    Remember: it is the second mouse that gets the cheese.....

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    In PowerPoint buttons only work in show mode.
    To run a macro in Edit mode you will EITHER need to:

    View > Macro > Run

    Create a button on the ribbon with XML (very basic tutorial)

    The recorder produces appalling code especially its use of ActiveWindow.Selection!!

    I would suggest you post your code here and people here will tell you how to modify it.

    If you want the code available to all presentations the best answer is an AddIn with a ribbon button. We have a free kit that helps you easily create this with your own macros.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location

    Here is the code

    Thanks for your comments John.
    I will investigate the ribbon button.

    as for posting my code, here is my first attempt at ppt vba.
    Suggestions are welcome, pointers on how to approach the object model are very much appreciated, and suggestions for comprehensive information resources will earn my undying gratitude.

    Sub Activate_Links()
    '
    ' Insert hyperlinks to slide 16 (the dashboard sitemap)
    '
    Dim mySlide As Object
    'Dim myRange As Object
    Dim qCode As String
    Dim myHLink As String

    qCode = GetQuickCode
    myHLink = "my link" & UCase(qCode)

    Set mySlide = ActivePresentation.Slides("DashboardNav")

    'set Qcode text
    mySlide.Shapes("TextBox 8").TextFrame.TextRange.Characters(Start:=12, Length:=3).Select
    ActiveWindow.Selection.TextRange.Text = qCode

    'set dashboard homepage text + hyperlink
    mySlide.Shapes("Textbox 8").TextFrame.TextRange.Characters(Start:=16, Length:=43).Select
    With ActiveWindow.Selection.TextRange
    .Text = "my next link" & qCode
    .ActionSettings(ppMouseClick).Hyperlink.Address = "another link"
    End With

    'set downloads hyperlink
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=61, Length:=9).Select
    myHLink = "link umpteen" & qCode & "/downloads"
    ActiveWindow.Selection.TextRange.ActionSettings(ppMouseClick).Hyperlink.Add ress = myHLink

    'set properties hyperlink
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=125 , Length:=10).Select
    myHLink = "link umpteen and 1" & qCode & "/properties"
    ActiveWindow.Selection.TextRange.ActionSettings(ppMouseClick).Hyperlink.Add ress = myHLink

    'set anomalies hyperlink
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=158 , Length:=15).Select
    myHLink = "and 2" & qCode & "/properties"
    ActiveWindow.Selection.TextRange.ActionSettings(ppMouseClick).Hyperlink.Add ress = myHLink

    End Sub
    Remember: it is the second mouse that gets the cheese.....

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    It's not clear what you are trying to do with Downloads, propertries and anomolies but it's unlikely you want to use ActiveWindow.Selection

    You hardly ever need to Select in PowerPoint

    How do you know the Slide's name is "dashboard Nav"?? (I doubt it unless you named it with code)

    Here's how to add text and a link to TextBox 8 on Slide 1

    [vba]Sub Activate_Links()

    Dim osld As Slide
    Dim sAddress1 As String
    Dim sLinkText1 As String

    Set osld = ActivePresentation.Slides(1)
    sAddress1 = "http://www.google.com"
    sLinkText1 = "Search"

    With osld.Shapes("TextBox 8").TextFrame.TextRange
    .Text = "Click Here to " & sLinkText1 & " please"
    With .Characters(15, 6).ActionSettings(ppMouseClick)
    .Action = ppActionHyperlink
    .Hyperlink.Address = sAddress1
    End With
    End With

    End Sub[/vba]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    Thanks John,
    You are a big help.

    What I have is a text box that is a site map for a website.
    the qcode is a three letter code that plugs into the hyperlink to set it for a particular client sub-page.

    I want to change the page from the default (eg. mywebsite/subscribers/any) to the specific client (eg mywebsite/subscribers/cl1), and repeat for the downloads, properties and anomalies sub-pages.

    but I have not earned sufficient privileges in this forum to post web links yet - hence the foncusion.

    Re the slide title, navigating through the locals window sowed me the slide name. I originally named it this, and the name has stuck - even though I have edited it since.

    Re selecting in PPT, I have yet a lot to learn here especially the difference between 'slide' and 'slides' etc, and knowing how to identify a property/object in the object explorer, and then working out how to call it correctly. (hence the reliance on the macro recorder). I am conversant enough now with excel vba to skip the recorder about half the time, and to remove almost all 'select' operations. Not so with PPT.

    Regards
    Tim
    Remember: it is the second mouse that gets the cheese.....

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Can you send me a slide that shows how you need to slide to be after the code runs with a given qcode and a second slide showning it before the code runs.

    info ATSIGN pptalchemy.co.uk

    Mark it FAO John and indicate it came from VBAX forum
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

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