Consulting

Results 1 to 9 of 9

Thread: BeforeSave events ?

  1. #1
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location

    BeforeSave events ?

    I've done some searching for PowerPoint help with the BeforeSave event (and in the vba help) but can't wrap my mind around it. I want to trigger my TEST macro below every time the user saves the file. Any ideas?

    Here's my code:
    [vba]
    Sub test()
    With ActivePresentation.Slides(1)
    Call DoVersionInfo("myInfo", 15, 560.75, 100, 32.125)
    End With
    End Sub

    [/vba]
    [vba]
    Sub DoVersionInfo(Nm As String, tp As Single, lft As Single, wdth As Single, ht As Single)
    Dim MyPath As String
    MyPath = Application.ActivePresentation.FullName
    With ActivePresentation.Slides(1).Shapes.Range.TextFrame.TextRange
    If Nm = "myInfo" Then
    .Delete
    End If
    End With
    With ActivePresentation.Slides(1).Shapes.AddLabel(msoTextOrientationHorizontal, Top:=tp, Left:=lft, Width:=wdth, Height:=ht)
    With .TextFrame.TextRange
    .Text = " -- " & MyPath
    .Characters(Start:=1, Length:=0).InsertDateTime DateTimeFormat:=ppDateTimeMMddyyHmm, InsertAsField:=msoTrue
    .ParagraphFormat.Alignment = ppAlignRight
    With .Paragraphs(1, 2).Font
    .Size = 10
    .Color = RGB(0, 48, 130)
    .Bold = msoTrue
    End With
    End With
    End With
    End Sub
    [/vba]
    Last edited by TrippyTom; 11-17-2006 at 05:33 PM.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Don't know if you still want this --

    I created a Module and a Class Module (the code needs to be cleaned up)

    Only thing I don't like is having to manually run the InitializeApp sub, so you could put it into an add in (No auto_open )

    But it does put the msg on the first slide before each save

    Paul

    [VBA]
    Option Explicit
    Dim X As New EventClassModule
    Sub InitializeApp()
    Set X.App = Application
    End Sub
    [/VBA]



    Class module

    [VBA]
    Public WithEvents App As Application

    Private Sub App_PresentationBeforeSave(ByVal Pres As Presentation, Cancel As Boolean)
    Call test(Pres)
    End Sub

    Sub test(p As Presentation)
    With p.Slides(1)
    Call DoVersionInfo(p, "myInfo", 15, 560.75, 100, 32.125)
    End With
    End Sub
    Sub DoVersionInfo(p As Presentation, Nm As String, tp As Single, lft As Single, wdth As Single, ht As Single)
    Dim MyPath As String
    MyPath = p.FullName
    With p.Slides(1).Shapes.Range.TextFrame.TextRange
    If Nm = "myInfo" Then
    .Delete
    End If
    End With
    With p.Slides(1).Shapes.AddLabel(msoTextOrientationHorizontal, Top:=tp, Left:=lft, Width:=wdth, Height:=ht)
    With .TextFrame.TextRange
    .Text = " -- " & MyPath
    .Characters(Start:=1, Length:=0).InsertDateTime DateTimeFormat:=ppDateTimeMMddyyHmm, InsertAsField:=msoTrue
    .ParagraphFormat.Alignment = ppAlignRight
    With .Paragraphs(1, 2).Font
    .Size = 10
    .Color = RGB(0, 48, 130)
    .Bold = msoTrue
    End With
    End With
    End With
    End Sub
    [/VBA]

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Paul_Hossler
    Only thing I don't like is having to manually run the InitializeApp sub, so you could put it into an add in (No auto_open )
    Couldn't you use the PresentationOpen event?

  4. #4
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    If you used it with an open event, wouldn't the time show when it was opened (i.e. current time) instead of when it was last saved?
    Office 2010, Windows 7
    goal: to learn the most efficient way

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Quote Originally Posted by xld
    Couldn't you use the PresentationOpen event?

    I think it'd be a Catch-22.

    You can't use PresentationOpen until you Dim a New object of the Class and Set the new object to Application

    So (at least when I tried to to verify using 2003) I couldn't get PresentationOpen to fire in order to init the New object since PresentionOpen wasn't available since the New object wasn't init-ed .

    PP isn't like Word or Excel where you can have an "auto_open" macro in a Module

    I'd love it if you could tell me how to have a PP "auto_open" capability in a presentation module

    Paul

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Install this addin

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    I installed the add in, and I do get the Msgbox about the presentation TEST1.PPT being added to the collection.

    However, I must not be doing something correctly

    The Presentation_Open event in the Class module in TEST1.PPT

    Private Sub App_PresentationOpen(ByVal Pres As Presentation)
    MsgBox "In Presentation_Open"
    End Sub

    Still won't fire when I open the PPT.

    Again, I still think that it's a Catch-22.

    Can you provide a little more detail for me? Thanks

    Also, I'm thinking about writing and loading an add-in that will attempt to run a "Auto_Open" macro, each time a PPT is opened, sort of like your add-in puts out a message.


    Paul
    Last edited by Paul_Hossler; 05-07-2007 at 08:48 AM.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    No it won't, but you can trap every or any presentation being opened, so you can be specifice about which and react to a particular presentation.

    What you are suggesting is exactly what I did. For some reason, auto_open runs in a ppa even though it won't in a ppt.

  9. #9
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    >>>No it won't, but you can trap every or any presentation being opened, so you can be specifice about which and react to a particular presentation.

    Difficulty is that any one who received the PPT would need the add-in installed, and that's going to be the problem. Word and Excel files can carry their "auto" macros with them, but PP doesn't.

    The last time I needed events in a presentation, I had to add a "Click to Init" button on the first screen to run the initializing procedure, but that was a little crude

    Paul

    PS: Next time I see Bill Gates, I'll mention this to him

Posting Permissions

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