PDA

View Full Version : BeforeSave events ?



TrippyTom
11-17-2006, 04:21 PM
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:

Sub test()
With ActivePresentation.Slides(1)
Call DoVersionInfo("myInfo", 15, 560.75, 100, 32.125)
End With
End Sub



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

Paul_Hossler
04-26-2007, 07:37 PM
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 :banghead: )

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

Paul


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




Class module


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

Bob Phillips
05-01-2007, 01:47 AM
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 :banghead: )
Couldn't you use the PresentationOpen event?

TrippyTom
05-01-2007, 08:34 AM
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?

Paul_Hossler
05-02-2007, 02:09 PM
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:doh: .

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

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

Paul

Bob Phillips
05-06-2007, 01:29 PM
Install this addin

Paul_Hossler
05-07-2007, 07:56 AM
I installed the add in, and I do get the Msgbox about the presentation TEST1.PPT being added to the collection. :clap:

However, I must not be doing something correctly:dunno

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

Bob Phillips
05-07-2007, 09:20 PM
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.

Paul_Hossler
05-08-2007, 07:55 AM
>>>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:beerchug: