beginner wants to write macro that run when presentation is viewed

M

mscir

I am a VB6 programmer but a complete ppt beginner. I have two things I'm
trying to accomplish:
1) write a small text file that contains the number of times a
presentation has been viewed, updating the file each time. and

2) displaying the number of times it's been viewed somewhere on the
presentation.

I know the VB subroutine code for writing and reading a file, but I
don't know how to call the subroutine each time the program is run, and
I don't know how to display the number of times the presentation has
been viewed.

Any help or urls would be greatly appreciated,
Mike
 
S

Steve Rindsberg

I am a VB6 programmer but a complete ppt beginner. I have two things I'm
trying to accomplish:
1) write a small text file that contains the number of times a
presentation has been viewed, updating the file each time. and

2) displaying the number of times it's been viewed somewhere on the
presentation.

I know the VB subroutine code for writing and reading a file, but I
don't know how to call the subroutine each time the program is run, and
I don't know how to display the number of times the presentation has
been viewed.

Getting code to run when a presentation is viewed is tricky. There's no
built-in way to do this in PPT as there is in Word/Excel.

You can trap events with an addin (see the link John posted) or, depending on
circumstances, you could have a "Start the Show" button on the first slide
trigger a macro that does the counter tracking and advances to the next slide.

As far as the counter tracking:

You can use a text file if you like, and I can imagine some good reasons for
doing so, but it might be simpler to keep the data attached to the PPT file
itself.

If you want to do that, you can use tags on the presentation itself:

Dim sTimesViewed as String

' Read the TimesViewed tag
sTimesViewed = ActivePresentation.Tags("TimesViewed")

If Len(sTimesViewed) > 0 then
' Increment it
sTimesViewed = Cstr(Clng(sTimesViewed) + 1)
Else
' Never viewed before, no tag there so start it at one
sTimesViewed = 1
End if

' And write back the tag
Call ActivePresentation.Tags.Add("TimesViewed", sTimesViewed)

' update the display
' supposing you have a shape named "Counter" on Slide 1:
ActivePresentation.Slides(1).Shapes("Counter").TextFrame.TextRange.Text = _
sTimesViewed

' Make sure changes are saved to PPT file
ActivePresentation.Save

========================================
 
M

Mike Scirocco

Steve said:
Getting code to run when a presentation is viewed is tricky. There's no
built-in way to do this in PPT as there is in Word/Excel.

You can trap events with an addin (see the link John posted) or, depending on
circumstances, you could have a "Start the Show" button on the first slide
trigger a macro that does the counter tracking and advances to the next slide.

As far as the counter tracking:

You can use a text file if you like, and I can imagine some good reasons for
doing so, but it might be simpler to keep the data attached to the PPT file
itself.

If you want to do that, you can use tags on the presentation itself:

Dim sTimesViewed as String

' Read the TimesViewed tag
sTimesViewed = ActivePresentation.Tags("TimesViewed")

If Len(sTimesViewed) > 0 then
' Increment it
sTimesViewed = Cstr(Clng(sTimesViewed) + 1)
Else
' Never viewed before, no tag there so start it at one
sTimesViewed = 1
End if

' And write back the tag
Call ActivePresentation.Tags.Add("TimesViewed", sTimesViewed)

' update the display
' supposing you have a shape named "Counter" on Slide 1:
ActivePresentation.Slides(1).Shapes("Counter").TextFrame.TextRange.Text = _
sTimesViewed

' Make sure changes are saved to PPT file
ActivePresentation.Save

========================================
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com

Thanks Steve,

that's very useful, much nicer than a text file, and automatically moves
with the presentation.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top