Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help In Inserting Slide Number Using VBA Code

4,145 views
Skip to first unread message

Gary

unread,
Nov 21, 2007, 10:15:02 AM11/21/07
to
I currently generate power point slide files using VBA Code from MS Access.
Once I have the power point file (ppt file), I can insert slide number and it
appears at the lower right corner of my slides manually. I want to do this
all from VBA Code.

Can someone show me how this can be done using VBA Code???

I have already recorded the macro for Insert Slide Number. I don't know how
to insert a macro into a ppt file via VBA Code. Even if I insert the macro
code in, I must run this code to take effect. How can I do this via VBA
code too.

Is there a way to run the VBA Code like on open event??

Your help is deeply appreicated.

Gary

David M. Marcovitz

unread,
Nov 21, 2007, 10:44:12 AM11/21/07
to
Gary,

I'm not sure I understand. Why do you want to run the VBA code from
PowerPoint. If you're running the VBA code in Access to create the show,
can't you run the code from Access to also add the page numbers. Just
note, what you get out of recording a macro is rarely directly usable.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/

=?Utf-8?B?R2FyeQ==?= <Ga...@discussions.microsoft.com> wrote in
news:4E1C91B8-6207-4980...@microsoft.com:

Brian Reilly, MVP

unread,
Nov 21, 2007, 12:18:26 PM11/21/07
to
Gary,
David is correct. If you are already running PPT from Access VBA code
then run the Insert Slide # code in a PPT file from Access. Sounds
like you already have the PPT application referenced, so just wrap the
Insert Slide # code somewhere inside that.

Or are we missing something in your question?

Brian Reilly, MVP

Gary

unread,
Nov 21, 2007, 12:42:01 PM11/21/07
to
I need the ability for users who open Power Point and reorder the slides.
Currently, I do generate slide number as the power point is generated. Now
if a user opens the power point and wants to re-order the position of the
slides, the page number will not re-order. They want the page number to
re-order.

Hope you can help !!1


Gary

Brian Reilly, MVP

unread,
Nov 21, 2007, 1:55:48 PM11/21/07
to
Gary,

Not sure you want to run this from, but you can get this code from the
Macro Recorder and decide how to deal with this. I suppose you'd want
to tie it to the Presentation.Save event or something like that.

If ActivePresentation.HasTitleMaster Then
With ActivePresentation.TitleMaster.HeadersFooters
.SlideNumber.Visible = msoTrue
End With
End If
With ActivePresentation.SlideMaster.HeadersFooters
.SlideNumber.Visible = msoTrue
End With
With ActivePresentation.Slides.Range.HeadersFooters
.SlideNumber.Visible = msoTrue
End With

Actually, you shouldn't have to tie it to any event, just run it from
inside your Access code when creating the presentation. Seems to work
here.

Brian Reilly, MVP

On Wed, 21 Nov 2007 09:42:01 -0800, Gary

Brian Reilly, MVP

unread,
Nov 21, 2007, 2:09:41 PM11/21/07
to
Gary,
I just tested this and this is better code.
You can figure out how to incorporate it into your existing Access
code I should think.

Option Explicit

Sub add_auto_page_numbering()
'By Brian Reilly, MVP

If ActivePresentation.HasTitleMaster Then
With ActivePresentation.TitleMaster.HeadersFooters
.SlideNumber.Visible = msoTrue
End With
End If
With ActivePresentation.SlideMaster.HeadersFooters
.SlideNumber.Visible = msoTrue
End With

End Sub

Brian Reilly, MVP


On Wed, 21 Nov 2007 09:42:01 -0800, Gary

Gary

unread,
Nov 21, 2007, 3:05:00 PM11/21/07
to
Thank You. It looks very similiar to something that I did a macro recorder
on.

I just have a few question for my understanding.

1) I could put this in my Access VBA Code, but does this need to be in the
point point file inorder for it to work correctly??? Like when a person
opens up a PPT file, and move slide 3 to the top. Then the old 3 will not
be page 1. When it do that even if the code was generated in Access???
Or is the secret to it is allowing .SlideNumber to be visible in PPT that
does it all for me????

2) Do you think I can place the SlideNumber at a differerent location by
using VBA Code to indicate the location to place a .text and have the .text
set to the .SlideNumber???

Thank You Very Much

John Wilson

unread,
Nov 22, 2007, 9:35:00 AM11/22/07
to
Slide numbers will update when slides are moved. It doesn't depend on how
they were added.

You can add a text box with a slide number to the master with vba

This adds a box at 10,10 width 40 and height 20

Sub slidnum()
Dim oshp As Shape
With ActivePresentation.SlideMaster.Shapes
Set oshp = .AddTextbox(msoTextOrientationHorizontal, 10, 10, 40, 20)
oshp.TextFrame.TextRange.InsertSlideNumber
End With
ActivePresentation.SlideMaster.HeadersFooters.SlideNumber.Visible = True
Set oshp = Nothing
End Sub
--
Amazing PPT Hints, Tips and Tutorials

http://www.PPTAlchemy.co.uk
http://www.technologytrish.co.uk
email john AT technologytrish.co.uk

Steve Rindsberg

unread,
Nov 22, 2007, 12:03:27 PM11/22/07
to

> 1) I could put this in my Access VBA Code, but does this need to be in the
> point point file inorder for it to work correctly??? Like when a person
> opens up a PPT file, and move slide 3 to the top. Then the old 3 will not
> be page 1. When it do that even if the code was generated in Access???
> Or is the secret to it is allowing .SlideNumber to be visible in PPT that
> does it all for me????

If you use slidenumber placeholders, they update themselves automatically within PPT
with no further code needed. (see John's example code)

If you create your own slide numbers by adding text, then they're "dumb" text ... they
won't update, so you'd need to go to uncommon lengths to get things to work in PPT
when users rearrange slides. Don't go there unless you really Really REALLY need to.

> 2) Do you think I can place the SlideNumber at a differerent location by
> using VBA Code to indicate the location to place a .text and have the .text
> set to the .SlideNumber???

Again, see John's code for inserting the slidenumber "placeholder" ... but yep, you
can change the .Left, .Top and other coordinates of the shape that contains the slide
number.

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


Brian Reilly, MVP

unread,
Nov 24, 2007, 6:48:04 AM11/24/07
to
Gary,

As John and Steve have pointed out, once you set the SlideNumber
Placeholder it is a live update in PPT when user changes order. I was
just suggesting that since you are creating original file from code in
Access that you turn on the SlideNumber placeholder in PPT from that
code.

Brian Reilly, MVP

Marcos Diaz

unread,
Oct 27, 2010, 11:03:09 PM10/27/10
to
Gary,

I have one request. I have a powerpoint presentacion which goes a slide 1,2,3,x, but also I have 2 picture in each slice and i want a code that count each picture with a textbox below.

Ex:

Slide 50


picture ((50*2)-1) picture (50*2)

Thanks in advance

> On Wednesday, November 21, 2007 10:15 AM Gar wrote:

> I currently generate power point slide files using VBA Code from MS Access.
> Once I have the power point file (ppt file), I can insert slide number and it
> appears at the lower right corner of my slides manually. I want to do this
> all from VBA Code.
>
> Can someone show me how this can be done using VBA Code???
>
> I have already recorded the macro for Insert Slide Number. I don't know how
> to insert a macro into a ppt file via VBA Code. Even if I insert the macro
> code in, I must run this code to take effect. How can I do this via VBA
> code too.
>
> Is there a way to run the VBA Code like on open event??
>
> Your help is deeply appreicated.
>
> Gary


>> On Wednesday, November 21, 2007 10:44 AM David M. Marcovitz wrote:

>> Gary,
>>
>> I'm not sure I understand. Why do you want to run the VBA code from
>> PowerPoint. If you're running the VBA code in Access to create the show,
>> can't you run the code from Access to also add the page numbers. Just
>> note, what you get out of recording a macro is rarely directly usable.
>>
>> --David
>>
>> --
>> David M. Marcovitz
>> Microsoft PowerPoint MVP
>> Director of Graduate Programs in Educational Technology
>> Loyola College in Maryland
>> Author of _Powerful PowerPoint for Educators_
>> http://www.PowerfulPowerPoint.com/
>>
>> =?Utf-8?B?R2FyeQ==?= <Ga...@discussions.microsoft.com> wrote in
>> news:4E1C91B8-6207-4980...@microsoft.com:


>>> On Wednesday, November 21, 2007 12:18 PM Brian Reilly, MVP wrote:

>>> Gary,
>>> David is correct. If you are already running PPT from Access VBA code
>>> then run the Insert Slide # code in a PPT file from Access. Sounds
>>> like you already have the PPT application referenced, so just wrap the
>>> Insert Slide # code somewhere inside that.
>>>
>>> Or are we missing something in your question?
>>>
>>> Brian Reilly, MVP
>>>
>>> On Wed, 21 Nov 2007 07:15:02 -0800, Gary
>>> <Ga...@discussions.microsoft.com> wrote:


>>>> On Wednesday, November 21, 2007 12:42 PM Gar wrote:

>>>> I need the ability for users who open Power Point and reorder the slides.
>>>> Currently, I do generate slide number as the power point is generated. Now
>>>> if a user opens the power point and wants to re-order the position of the
>>>> slides, the page number will not re-order. They want the page number to
>>>> re-order.
>>>>
>>>> Hope you can help !!1
>>>>
>>>>
>>>> Gary
>>>>
>>>>
>>>>
>>>>
>>>> "Brian Reilly, MVP" wrote:


>>>>> On Wednesday, November 21, 2007 1:55 PM Brian Reilly, MVP wrote:

>>>>> Gary,
>>>>>

>>>>> Not sure you want to run this from, but you can get this code from the
>>>>> Macro Recorder and decide how to deal with this. I suppose you'd want
>>>>> to tie it to the Presentation.Save event or something like that.
>>>>>

>>>>> If ActivePresentation.HasTitleMaster Then
>>>>> With ActivePresentation.TitleMaster.HeadersFooters
>>>>> .SlideNumber.Visible = msoTrue
>>>>> End With
>>>>> End If
>>>>> With ActivePresentation.SlideMaster.HeadersFooters
>>>>> .SlideNumber.Visible = msoTrue
>>>>> End With

>>>>> With ActivePresentation.Slides.Range.HeadersFooters


>>>>> .SlideNumber.Visible = msoTrue
>>>>> End With
>>>>>

>>>>> Actually, you shouldn't have to tie it to any event, just run it from
>>>>> inside your Access code when creating the presentation. Seems to work
>>>>> here.
>>>>>

>>>>> Brian Reilly, MVP
>>>>>
>>>>> On Wed, 21 Nov 2007 09:42:01 -0800, Gary
>>>>> <Ga...@discussions.microsoft.com> wrote:


>>>>>> On Wednesday, November 21, 2007 2:09 PM Brian Reilly, MVP wrote:

>>>>>> Gary,
>>>>>> I just tested this and this is better code.
>>>>>> You can figure out how to incorporate it into your existing Access
>>>>>> code I should think.
>>>>>>
>>>>>> Option Explicit
>>>>>>
>>>>>> Sub add_auto_page_numbering()
>>>>>> 'By Brian Reilly, MVP
>>>>>>
>>>>>> If ActivePresentation.HasTitleMaster Then
>>>>>> With ActivePresentation.TitleMaster.HeadersFooters
>>>>>> .SlideNumber.Visible = msoTrue
>>>>>> End With
>>>>>> End If
>>>>>> With ActivePresentation.SlideMaster.HeadersFooters
>>>>>> .SlideNumber.Visible = msoTrue
>>>>>> End With
>>>>>>
>>>>>> End Sub
>>>>>>
>>>>>> Brian Reilly, MVP
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Wed, 21 Nov 2007 09:42:01 -0800, Gary
>>>>>> <Ga...@discussions.microsoft.com> wrote:


>>>>>>> On Wednesday, November 21, 2007 3:05 PM Gar wrote:

>>>>>>> Thank You. It looks very similiar to something that I did a macro recorder
>>>>>>> on.
>>>>>>>
>>>>>>> I just have a few question for my understanding.
>>>>>>>
>>>>>>> 1) I could put this in my Access VBA Code, but does this need to be in the
>>>>>>> point point file inorder for it to work correctly??? Like when a person
>>>>>>> opens up a PPT file, and move slide 3 to the top. Then the old 3 will not
>>>>>>> be page 1. When it do that even if the code was generated in Access???
>>>>>>> Or is the secret to it is allowing .SlideNumber to be visible in PPT that
>>>>>>> does it all for me????
>>>>>>>
>>>>>>> 2) Do you think I can place the SlideNumber at a differerent location by
>>>>>>> using VBA Code to indicate the location to place a .text and have the .text
>>>>>>> set to the .SlideNumber???
>>>>>>>
>>>>>>> Thank You Very Much
>>>>>>>
>>>>>>>
>>>>>>> Gary
>>>>>>>
>>>>>>> "Brian Reilly, MVP" wrote:


>>>>>>>> On Thursday, November 22, 2007 9:35 AM john AT technologytrish.co DOT uk wrote:

>>>>>>>> Slide numbers will update when slides are moved. It doesn't depend on how
>>>>>>>> they were added.
>>>>>>>>
>>>>>>>> You can add a text box with a slide number to the master with vba
>>>>>>>>
>>>>>>>> This adds a box at 10,10 width 40 and height 20
>>>>>>>>
>>>>>>>> Sub slidnum()
>>>>>>>> Dim oshp As Shape
>>>>>>>> With ActivePresentation.SlideMaster.Shapes
>>>>>>>> Set oshp = .AddTextbox(msoTextOrientationHorizontal, 10, 10, 40, 20)
>>>>>>>> oshp.TextFrame.TextRange.InsertSlideNumber
>>>>>>>> End With
>>>>>>>> ActivePresentation.SlideMaster.HeadersFooters.SlideNumber.Visible = True
>>>>>>>> Set oshp = Nothing
>>>>>>>> End Sub
>>>>>>>> --
>>>>>>>> Amazing PPT Hints, Tips and Tutorials
>>>>>>>>
>>>>>>>> http://www.PPTAlchemy.co.uk
>>>>>>>> http://www.technologytrish.co.uk
>>>>>>>> email john AT technologytrish.co.uk
>>>>>>>>
>>>>>>>>
>>>>>>>> "Gary" wrote:


>>>>>>>>> On Saturday, November 24, 2007 4:24 AM Steve Rindsberg wrote:

>>>>>>>>> If you use slidenumber placeholders, they update themselves automatically within PPT
>>>>>>>>> with no further code needed. (see John's example code)
>>>>>>>>>
>>>>>>>>> If you create your own slide numbers by adding text, then they're "dumb" text ... they
>>>>>>>>> won't update, so you'd need to go to uncommon lengths to get things to work in PPT
>>>>>>>>> when users rearrange slides. Don't go there unless you really Really REALLY need to.
>>>>>>>>>
>>>>>>>>>

>>>>>>>>> Again, see John's code for inserting the slidenumber "placeholder" ... but yep, you
>>>>>>>>> can change the .Left, .Top and other coordinates of the shape that contains the slide
>>>>>>>>> number.
>>>>>>>>>
>>>>>>>>> -----------------------------------------
>>>>>>>>> Steve Rindsberg, PPT MVP
>>>>>>>>> PPT FAQ: www.pptfaq.com
>>>>>>>>> PPTools: www.pptools.com
>>>>>>>>> ================================================


>>>>>>>>>> On Saturday, November 24, 2007 6:48 AM Brian Reilly, MVP wrote:

>>>>>>>>>> Gary,
>>>>>>>>>>

>>>>>>>>>> As John and Steve have pointed out, once you set the SlideNumber
>>>>>>>>>> Placeholder it is a live update in PPT when user changes order. I was
>>>>>>>>>> just suggesting that since you are creating original file from code in
>>>>>>>>>> Access that you turn on the SlideNumber placeholder in PPT from that
>>>>>>>>>> code.
>>>>>>>>>>
>>>>>>>>>> Brian Reilly, MVP
>>>>>>>>>>
>>>>>>>>>> On Wed, 21 Nov 2007 12:05:00 -0800, Gary
>>>>>>>>>> <Ga...@discussions.microsoft.com> wrote:


>>>>>>>>>> Submitted via EggHeadCafe - Software Developer Portal of Choice
>>>>>>>>>> SharePoint WorkFlow Basics
>>>>>>>>>> http://www.eggheadcafe.com/tutorials/aspnet/1fa263fb-d7a6-40f5-8875-356f75d9fca9/sharepoint-workflow-basics.aspx

Joseph M. Newcomer

unread,
Oct 30, 2010, 2:05:20 PM10/30/10
to
Is there a point to this post? What does it mean

"Re: Gary, As John and Steve have pointed out, once you set the"

Set the WHAT?

Titles of posts are short and to the point; CONTENT of the post is in the body. Attempts
to put content in the title are doomed.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

0 new messages