Consulting

Results 1 to 20 of 20

Thread: powerpoint 2007 add-in (newbie questions)

  1. #1
    VBAX Regular
    Joined
    Feb 2011
    Posts
    7
    Location

    powerpoint 2007 add-in (newbie questions)

    Hi,
    I am a VB.NET developer but I am new to VBA and I have quick simple questions looking for an answer:
    I have an add-in in powerpoint 2007:
    1- I have a button that load a form, how I change the button icon ?
    2- How I add another button in the ribbon ?
    3- how I decide wich module to load when I click on the add-in button in the ribbon bar button ?
    looking only for small tips


    Thanks

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    It sound like you want to add commands to the ribbon to call your add in's subs

    It's different than the previous CommandBar logic

    There is a 'Office 2007 Ribbon UI' forum here that has more information about the Fluent interface

    Basically you

    1. Write the PP macro file (.pptm)
    2. Use the CustomUI editor

    http://openxmldeveloper.org/articles...muieditor.aspx

    to add XML to your .pptm

    Adding the XML is not impossible (after all, I can do the simple basic stuff), but it is very finicky

    3. If you get stuck, post a simple version of the add in and the forum members will be glad to assist.

    4. Additional night time reading -- Ken's book has a sample chapter available

    http://www.excelguru.ca/node/93

    as does Stephen Bullen

    http://www.oaltd.co.uk/Spreads/Excel...ogRef_ch14.pdf


    Both very insightful, and worth ordering (don't seem to be on the shelf in my local book store)


    MS also has Office Fluent User Interface Developer Portal

    http://msdn.microsoft.com/en-us/office/aa905530.aspx

    Paul

  3. #3
    VBAX Regular
    Joined
    Feb 2011
    Posts
    7
    Location
    Many Thanks Paul

    I found that using the CUI tool there is XML in the add-in file, in general the onAction="action_name" decide which sub to execute when user click on the button
    [vba]
    Sub action_name(control As IRibbonControl)
    code here...
    End Sub[/vba]
    one question now please, there is code that get executed in a module like this

    [vba]Option Explicit

    #If VBA7 Then
    Sub sub_name1
    #Else
    Sub sub_name2
    #End If
    sub_name3
    End Sub[/vba]
    how and when this part get executed ?

    Please advise

  4. #4
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    That's a confusing indent structure for what's going on.

    The procedure is called sub_name1 if the project is compiled in VBA7, otherwise the procedure is called sub_name2.

    In both cases, it runs a procedure called sub_name3.

    It would be more clear if it looked like this:
    #If VBA7 then
      Sub sub_name1
    #Else
      Sub sub_name2
    #End If
        sub_name3
    End Sub
    As for how and when it gets executed... it depends on when it's called, like any other procedure. The # marks are simply conditional compilation statements.

  5. #5
    VBAX Regular
    Joined
    Feb 2011
    Posts
    7
    Location
    the format is confusing because I used the VBA tags , it insist to display it in that way!

    About the code itself , it exists in one of the modules and I want to know the order of executing codes like that in modules, by other meaning which module code fire first and whether I am able to decide or not -- bear with me plz I an new

  6. #6
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Ahh. I'm new to this forum too, so I didn't know about the VBA tag, having only used the CODE tag.

    I think you're asking a concept question. I will try to answer, although I am not 100% sure of this.

    VBA modules are compiled at run-time (although it is good practice to compile your entire project to make sure you don't have some silly coding mistakes).

    The entire module will be compiled at the point you call some procedure within the module.

    Above that, I think, it would determine what kind of events/automacros were called in your project.

    I am less familiar with powerpoint events than I am with Word, so I can't be much more specific than that.

    The general concept is that the modules are compiled "as needed"... and the "as needed" order really depends on what, if anything, you are calling both a) when the project is loaded and b) when you've called a particular macro.

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    What that does is run sub_name1 if you have PPT 2010 and sub_name2 if you have any other version
    sub_name3 always runs.

    It is often used to declare APIs for 2010 64bit that need to be PtrSafe but wouldn't compile in earlier versions
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Really? Correct me if I'm wrong, John... but isn't it only declaring sub_name1 vs. subname2?

    So in the 64 bit version, you would call sub_name1 to run sub_name3, but otherwise you would call sub_name2 to run sub_name3.

    I'm not sure why you'd use this particular construct, honestly.

    Where I've seen this usage is when you need to declare a return value or a parameter differently, but the routine is named the same. For example:

    #If VBA7 then
      Sub MySub(myVal as LongPtr)
    #Else
      Sub MySub(myVal as Long)
    #End If
    Or am I missing something?

  9. #9
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    As it stands it wouldn't work at all (this is also why it didn't format)

    My assumption was that the code was to run a different sub (sub_name1) if the user had PPT 2010 and another if the user had an earlier version (sub_name2). This is often useful as there are many new features in 2010 that won't compile in 2007 and also the possibility of 64 bit versions that need special API calls

    [vba]Sub altsubs()
    #If VBA7 Then
    sub_name1
    #Else
    sub_name2
    #End If
    End Sub[/vba]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  10. #10
    VBAX Regular
    Joined
    Feb 2011
    Posts
    7
    Location
    Many Thanks for all replies:

    that was like John Wilson said.

    but yes I was asking about the concept not a particular codeI am still not sure which module fire first or based on what ,

    I know about auto_open but I really like to know the sequence VBA code get executed modules that confuse me as I come from other languages

  11. #11
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    I think the formatting issue is one of the custom VBA code on this board rather than something about the code which wouldn't work. Technically that construct could work.

    The following code (which I have in use and know works) looks "wrong" according to the VBA code on this board.

    [vba]
    #If VBA7 Then
    Private Function fCreateIPicture(ByVal hPic As LongPtr) As IPicture
    #Else
    Private Function dfCreateIPicture(ByVal hPic As Long) As IPicture
    #End If
    'do stuff
    End Function
    [/vba]
    That said, Welliam, you should look up application events in powerpoint on MSDN.

    There is a particular order, but it's a big discussion and not easily summed up. If you have a more specific question, it would be easier to answer.

  12. #12
    VBAX Regular
    Joined
    Feb 2011
    Posts
    7
    Location
    ok simpler question can I write code in a module without using an event and get executed at start up (something like the main procedure in C++)

    also without using auto_open.

  13. #13
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Start up of what? Powerpoint? A presentation?

    I believe the order of operations are:

    1. Powerpoint starts
    2. Global powerpoint addins are loaded (with each Auto_Open macro, if any, of those addins being run as they are loaded)
    3. Powerpoint opens a blank presentation if nothing was called, otherwise it opens the presentation called and then runs Auto_Open if it exists in the opened presentation)

    If you check out http://msdn.microsoft.com/en-us/library/ff746018.aspx you can write event code to access additional events, if desired.

    However, it really depends on what you want to do. You want code to run at Powerpoint startup? You need an addin that has code in a procedure called Auto_Open.

    Depending on the version, you'll need to develop your code in a powerpoint presentation that allows macros... and then you'll need to save it as a power point addin.

    From there, you will need to load your addin (2007/2010, show the developer toolbar, click the addins button, then add your addin).

    There are a whole host of issues with this, including whether your addin lives in a trusted location, etc.

    But the basic structure is:

    1. Write code in pptm (using Auto_Open)
    2. save pptm
    3. save as ppam
    4. tell Powerpoint to load ppam
    Last edited by Frosty; 02-17-2011 at 05:28 PM.

  14. #14
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Welliam --

    It sounds like your add in is only used when not in slide presentation mode. I have a bunch of macros (thanks to John W's help) to do various things like remove notes, etc. and i have them collected into an add in

    It sounds like there's a need to do some initialization when your add in loads, OR is it at some other time (e.g. like opening a presentation) ?

    I'm confused about the reasoning behind needing auto_open

    For what it's worth, I've used the Fluent Ribbon Load callback to create something that works as an Auto Open, but without having to have an add in

    Sample attached if you're interested, just save and remove the .zip part

    If it is just a basic PP addin that you're looking to do, I'll be glad to make up a simple add in with some basic XML. Just let me know

    Since you are coming from other languages, some more detail and the 'What' and especially the 'Why' would be helpful, because VBA and the Office apps are different

    Paul
    Attached Files Attached Files

  15. #15
    VBAX Regular
    Joined
    Feb 2011
    Posts
    7
    Location
    thanks alot for all replies:
    @Paul, this is for ribbon load, can you tell me please what is the event for add-in load ?

  16. #16
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    That's clever, Paul. Although I remember reading MS is not a fan of popups during the ribbon onload event, so you might be limited in that approach.

    Weillum: addin load event is Auto_Open.

    But that fires when the addin is loaded. For example, you will need to create:
    1. Auto_Load in MyAddin.pptm
    2. Then save MyAddin.pptm AS MyAddin.ppam
    3. Then load MyAddin.ppam

  17. #17
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Quote Originally Posted by Welliam
    thanks alot for all replies:
    @Paul, this is for ribbon load, can you tell me please what is the event for add-in load ?
    Your addin can use the Ribbon's OnLoad sub in lieu of an auto open. When the add in (.PPMA) loads, OnLoad should run.

    The XML doesn't always need to add buttons etc, but it can

    My add in adds buttons etc to a new tab to to make calling my macros easier

    Paul

  18. #18
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    this is a simple pptm file that adds tab and buttons to the ribbon that you can play with

    save it without the .zip, and open it in pp and save as a ppam file

    auto_open runs when you load the add in (but not when you open the pptm file). There is no auto_load (at least in 2010)

    paul
    Attached Files Attached Files

  19. #19
    VBAX Regular
    Joined
    Feb 2011
    Posts
    7
    Location
    Many thanks to every one, I am really happy from all great contribution

  20. #20
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Quote Originally Posted by Frosty
    That's clever, Paul. Although I remember reading MS is not a fan of popups during the ribbon onload event, so you might be limited in that approach.
    Not sure about the Popups during the OnLoad (don't reallyy do it), but this way there'e no need for an add in to be on another computer, only 'problem' is that the other user might have to enable macros

    Paul

Posting Permissions

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