Export/import slide master slide number

  • Thread starter Thread starter David Pooley
  • Start date Start date
D

David Pooley

I have a macro that exports a PowerPoint presentation to XML so that the
text can be translated. Once translation is complete, another macro imports
the translated text back in to the slides. Is there any way to know that
when I access the text of a shape on the slide master that the "<#>" is
intended to display as the slide number in the presentation? PowerPoint
obviously "knows" that this is a field as it highlights it as such (clicking
any part of it highlights all the text) but I don't know how to get at that
information through VBA.

In my case, the following ...

ActivePresentation.SlideMaster.Shapes(5).TextFrame.TextRange.Characters

.... returns some text which contains "<#>" somewhere in the middle but how
am I supposed to know that this is the slide number? If I import some text
which just has "<#>" in it, PowerPoint doesn't change this to be the slide
number so "<#>" shows up on every slide instead of the number.

The solution I'm looking at is to assume that <#> is the slide number and
use the InsertSlideNumber method to replace it in the text but I was
wondering if there was any way to be certain ...

Thanks

David
 
The solution I'm looking at is to assume that said:
use the InsertSlideNumber method to replace it in the text but I was
wondering if there was any way to be certain ...

Look at the ascii value of each character in the string; they may look like
the usual < and > characters, but they're not. Instead of 60 and 62, they're
139 and 155.

I expect that should be enough to get you over the hump, right?


--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
This might help. The open angle bracket character < is ASCII code 60.
The open angle bracket character used for <#> when it is a page number is
ASCII code 139.
--David

--
David M. Marcovitz, Ph.D.
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
Steve Rindsberg said:
Look at the ascii value of each character in the string; they may look like
the usual < and > characters, but they're not. Instead of 60 and 62, they're
139 and 155.

I expect that should be enough to get you over the hump, right?

Unfortunately not. I'm guessing it's an internal PowerPoint thing that's not
accessible from VBA. I ran the following in immediate mode:

ActivePresentation.SlideMaster.Shapes(5).TextFrame.TextRange.Characters =
ActivePresentation.SlideMaster.Shapes(5).TextFrame.TextRange.Characters

This, however, changed the slide number to the "<#>" on all my slides. Rats.

PowerPoint just seems to "know" that the slide number appears at that
particular character position in the string. Looks like I may be using a
brute force/guessing technique.

David
 
David,

See below ....
Unfortunately not. I'm guessing it's an internal PowerPoint thing that's not
accessible from VBA. I ran the following in immediate mode:

ActivePresentation.SlideMaster.Shapes(5).TextFrame.TextRange.Characters =
ActivePresentation.SlideMaster.Shapes(5).TextFrame.TextRange.Characters

This, however, changed the slide number to the "<#>" on all my slides. Rats.

PowerPoint just seems to "know" that the slide number appears at that
particular character position in the string. Looks like I may be using a
brute force/guessing technique.

Here are a couple subs/functions that'll tell you whether a given shape is a
slide number placeholder and create one for you. Tested in PPT2000, would need
some mods for later versions, especially if multiple masters are in use.

Watch out for linebreaks ....

Function IsPageNumber(oSh As Shape) As Boolean
' is the passed shape a page number or not?

Dim x As Long

If oSh.PlaceholderFormat.Type = ppPlaceholderSlideNumber Then
If InStr(oSh.TextFrame.TextRange.Text, Chr$(139)) > 0 Then
If InStr(oSh.TextFrame.TextRange.Text, Chr$(155)) > 0 Then
' assume it's a number
IsPageNumber = True
End If
End If
End If
End Function

Sub TestIsPageNumber()
Dim oSh As Shape
For Each oSh In ActivePresentation.SlideMaster.Shapes
If IsPageNumber(oSh) Then
Debug.Print oSh.Name & " <<--- THIS ONE"
Else
Debug.Print oSh.Name
End If
Next oSh
End Sub

Sub MakePageNumber()
Dim oSh As Shape

' Errors if there's already a slide number placeholder
' You might want to deal with it more cleverly than this

On Error Resume Next
Set oSh =
ActivePresentation.SlideMaster.Shapes.AddPlaceholder(Type:=ppPlaceholderSlideNu
mber)

' format it/position it to suit ...
oSh.Left = 100

End Sub


--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
Hi Steve,

Thanks for all your efforts on this. Unfortunately, the shape in question
isn't a placeholder. Just a plain old shape. PowerPoint let's you put the
slide number even in a non-placeholder shape. Hmmm.

I'm going to settle for the following:

Sub SortOutSlideNumber()
Dim oSh As Shape
Dim nSN As Long
Dim nStart As Long
On Error Resume Next
For Each oSh In ActivePresentation.SlideMaster.Shapes
nStart = 1
Do
nSN = 0
nSN = InStr(nStart, oSh.TextFrame.TextRange.Characters, "<#>")
If nSN > 0 Then
oSh.TextFrame.TextRange.Characters(nSN, 3).InsertSlideNumber
nStart = nSN + 1
End If
Loop Until nSN = 0
Next oSh
End Sub

It seems to work for me. The only downside is that if you actually want to
include the text "<#>" somewhere on your slide master, it's not going to
work However, I'm prepared to accept that this is a very remote possibility
:-)

Thanks again

David
 
It seems to work for me. The only downside is that if you actually want to
include the text "<#>" somewhere on your slide master, it's not going to
work However, I'm prepared to accept that this is a very remote possibility

Considering that it's not really <#> but a couple of weirdo characters that are
normally never used in English, it's pretty unlikely.


--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
Back
Top