Export/import slide master slide number

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
 
D

David M. Marcovitz

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/
 
D

David Pooley

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
 
D

David Pooley

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
 

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