Welcome to Windows Help!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

VBA - How to subscript?

 
   Windows Help (Home) -> Microsoft Powerpoint RSS
Next:  TRUE/ FALSE in check boxes do not toggle  
Author Message
Mel

External


Since: Apr 8, 2009
Posts: 2



(Msg. 1) Posted: Sun Nov 22, 2009 8:11 pm
Post subject: VBA - How to subscript?
Archived from groups: microsoft>public>powerpoint (more info?)

I'm replacing a character with another and then subscripting that new
character. My code seems to work fine except when the object has
multiple paragraphs. The last routine below (SubScriptMe) is called to
subscript, but with multiple paragraphs it's counting the paragraph
marker and screwing up the count to subscript the correct character.
<argh!>

Is there a better way to accomplish this? Or is there a way to work
around multiple paragraphs.

Thanks,
Melina
(code below)

Sub SearchReplaceSubscript()
Dim oSld As Slide
Dim oShp As Shape
Dim sSearchFor As String
Dim sReplaceWith As String
sSearchFor = ChrW$(8482)
sReplaceWith = ChrW$(9674)

For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
Call SearchReplace(oShp, sSearchFor, sReplaceWith)
Next oShp
Next oSld
End Sub

Sub SearchReplace(oShp As Object, sSearchFor As String, sReplaceWith
As String)
Dim oTxtRng As TextRange
Dim oTmpRng As TextRange
Dim iCntr As Integer
Dim iRow As Integer
Dim iCol As Integer
Dim oShpTmp As Shape

On Error Resume Next
Select Case oShp.Type

Case 19
For iRow = 1 To oShp.Table.Rows.Count
For iCol = 1 To oShp.Table.Rows(iRow).Cells.Count
Set oTxtRng = oShp.Table.Rows(iRow).Cells
(iCol).Shape.TextFrame.TextRange
Set oTmpRng = oTxtRng.Replace(FindWhat:=sSearchFor, _
Replacewhat:=sReplaceWith, WholeWords:=False)
Do While Not oTmpRng Is Nothing
Set oTmpRng = oTxtRng.Replace(FindWhat:=sSearchFor, _
Replacewhat:=sReplaceWith, _
After:=oTmpRng.Start + oTmpRng.Length, _
WholeWords:=False)
Call SubScriptMe(oTxtRng, sReplaceWith)
Loop
Next
Next

Case msoGroup
For iCntr = 1 To oShp.GroupItems.Count
Call SearchReplace(oShp.GroupItems(iCntr), sSearchFor,
sReplaceWith)
Next iCntr

Case 21
For iCntr = 1 To oShp.Diagram.Nodes.Count
Call SearchReplace(oShp.Diagram.Nodes(iCntr).TextShape,
sSearchFor, sReplaceWith)
Next iCntr

Case Else
If oShp.HasTextFrame Then
If oShp.TextFrame.HasText Then
Set oTxtRng = oShp.TextFrame.TextRange
Set oTmpRng = oTxtRng.Replace(FindWhat:=sSearchFor, _
Replacewhat:=sReplaceWith, WholeWords:=False)
Do While Not oTmpRng Is Nothing
Set oTmpRng = oTxtRng.Replace(FindWhat:=sSearchFor, _
Replacewhat:=sReplaceWith, _
After:=oTmpRng.Start + oTmpRng.Length, _
WholeWords:=False)
Loop
Call SubScriptMe(oTxtRng, sReplaceWith)
End If
End If

End Select
End Sub

Sub SubScriptMe(oTxtRng As TextRange, sReplaceWith As String)
Dim iPos As Long
iPos = InStr(oTxtRng, sReplaceWith)
Do While iPos > 0
oTxtRng.Characters(iPos, 1).Font.SuperScript = True
iPos = InStr(iPos + 1, oTxtRng, sReplaceWith)
Loop
End Sub

 >> Stay informed about: VBA - How to subscript? 
Back to top
Login to vote
Steve Rindsberg

External


Since: Nov 8, 2008
Posts: 108



(Msg. 2) Posted: Mon Nov 23, 2009 3:43 am
Post subject: Re: VBA - How to subscript?
Archived from groups: per prev. post (more info?)

Instead of iterating through all of the characters in the range, try
something like:

For x = 1 to oTxtRng.Paragraphs.Count
Set oTmpRange = oTxtRng.Paragraphs(x)

' then work your magic on oTmpRng

Next

In article <80743adb-7716-47de-bcb2-
6ddb46fc3044.cut.RemoveThis@d10g2000yqh.googlegroups.com>, Mel wrote:
> I'm replacing a character with another and then subscripting that new
> character. My code seems to work fine except when the object has
> multiple paragraphs. The last routine below (SubScriptMe) is called to
> subscript, but with multiple paragraphs it's counting the paragraph
> marker and screwing up the count to subscript the correct character.
> <argh!>
>
> Is there a better way to accomplish this? Or is there a way to work
> around multiple paragraphs.
>
> Thanks,
> Melina
> (code below)
>
> Sub SearchReplaceSubscript()
> Dim oSld As Slide
> Dim oShp As Shape
> Dim sSearchFor As String
> Dim sReplaceWith As String
> sSearchFor = ChrW$(8482)
> sReplaceWith = ChrW$(9674)
>
> For Each oSld In ActivePresentation.Slides
> For Each oShp In oSld.Shapes
> Call SearchReplace(oShp, sSearchFor, sReplaceWith)
> Next oShp
> Next oSld
> End Sub
>
> Sub SearchReplace(oShp As Object, sSearchFor As String, sReplaceWith
> As String)
> Dim oTxtRng As TextRange
> Dim oTmpRng As TextRange
> Dim iCntr As Integer
> Dim iRow As Integer
> Dim iCol As Integer
> Dim oShpTmp As Shape
>
> On Error Resume Next
> Select Case oShp.Type
>
> Case 19
> For iRow = 1 To oShp.Table.Rows.Count
> For iCol = 1 To oShp.Table.Rows(iRow).Cells.Count
> Set oTxtRng = oShp.Table.Rows(iRow).Cells
> (iCol).Shape.TextFrame.TextRange
> Set oTmpRng = oTxtRng.Replace(FindWhat:=sSearchFor, _
> Replacewhat:=sReplaceWith, WholeWords:=False)
> Do While Not oTmpRng Is Nothing
> Set oTmpRng = oTxtRng.Replace(FindWhat:=sSearchFor, _
> Replacewhat:=sReplaceWith, _
> After:=oTmpRng.Start + oTmpRng.Length, _
> WholeWords:=False)
> Call SubScriptMe(oTxtRng, sReplaceWith)
> Loop
> Next
> Next
>
> Case msoGroup
> For iCntr = 1 To oShp.GroupItems.Count
> Call SearchReplace(oShp.GroupItems(iCntr), sSearchFor,
> sReplaceWith)
> Next iCntr
>
> Case 21
> For iCntr = 1 To oShp.Diagram.Nodes.Count
> Call SearchReplace(oShp.Diagram.Nodes(iCntr).TextShape,
> sSearchFor, sReplaceWith)
> Next iCntr
>
> Case Else
> If oShp.HasTextFrame Then
> If oShp.TextFrame.HasText Then
> Set oTxtRng = oShp.TextFrame.TextRange
> Set oTmpRng = oTxtRng.Replace(FindWhat:=sSearchFor, _
> Replacewhat:=sReplaceWith, WholeWords:=False)
> Do While Not oTmpRng Is Nothing
> Set oTmpRng = oTxtRng.Replace(FindWhat:=sSearchFor, _
> Replacewhat:=sReplaceWith, _
> After:=oTmpRng.Start + oTmpRng.Length, _
> WholeWords:=False)
> Loop
> Call SubScriptMe(oTxtRng, sReplaceWith)
> End If
> End If
>
> End Select
> End Sub
>
> Sub SubScriptMe(oTxtRng As TextRange, sReplaceWith As String)
> Dim iPos As Long
> iPos = InStr(oTxtRng, sReplaceWith)
> Do While iPos > 0
> oTxtRng.Characters(iPos, 1).Font.SuperScript = True
> iPos = InStr(iPos + 1, oTxtRng, sReplaceWith)
> Loop
> End Sub


==============================
PPT Frequently Asked Questions
[URL="http://www.pptfaq.com/"]http://www.pptfaq.com/[/URL]

PPTools add-ins for PowerPoint
[URL="http://www.pptools.com/"]http://www.pptools.com/[/URL]

 >> Stay informed about: VBA - How to subscript? 
Back to top
Login to vote
Mel

External


Since: Apr 8, 2009
Posts: 2



(Msg. 3) Posted: Mon Nov 23, 2009 11:59 am
Post subject: Re: VBA - How to subscript?
Archived from groups: per prev. post (more info?)

Wow, I'd of never thought of counting paragraphs and attacking them
individually. You're the best!

Thanks,
Melina

On Nov 22, 9:43 pm, Steve Rindsberg wrote:
> Instead of iterating through all of the characters in the range, try
> something like:
>
> For x = 1 to oTxtRng.Paragraphs.Count
>   Set oTmpRange = oTxtRng.Paragraphs(x)
>
>   ' then work your magic on oTmpRng
>
> Next
>
> In article <80743adb-7716-47de-bcb2-
>
>
>
> 6ddb46fc3....Remove.TakeThisOut@d10g2000yqh.googlegroups.com>, Mel wrote:
> > I'm replacing a character with another and then subscripting that new
> > character. My code seems to work fine except when the object has
> > multiple paragraphs. The last routine below (SubScriptMe) is called to
> > subscript, but with multiple paragraphs it's counting the paragraph
> > marker and screwing up the count to subscript the correct character.
> > <argh!>
>
> > Is there a better way to accomplish this? Or is there a way to work
> > around multiple paragraphs.
>
> > Thanks,
> > Melina
> > (code below)
>
> > Sub SearchReplaceSubscript()
> > Dim oSld As Slide
> > Dim oShp As Shape
> > Dim sSearchFor As String
> > Dim sReplaceWith  As String
> > sSearchFor = ChrW$(8482)
> > sReplaceWith = ChrW$(9674)
>
> > For Each oSld In ActivePresentation.Slides
> >     For Each oShp In oSld.Shapes
> >         Call SearchReplace(oShp, sSearchFor, sReplaceWith)
> >     Next oShp
> > Next oSld
> > End Sub
>
> > Sub SearchReplace(oShp As Object, sSearchFor As String, sReplaceWith
> > As String)
> > Dim oTxtRng As TextRange
> > Dim oTmpRng As TextRange
> > Dim iCntr As Integer
> > Dim iRow As Integer
> > Dim iCol As Integer
> > Dim oShpTmp As Shape
>
> > On Error Resume Next
> > Select Case oShp.Type
>
> > Case 19
> >  For iRow = 1 To oShp.Table.Rows.Count
> >   For iCol = 1 To oShp.Table.Rows(iRow).Cells.Count
> >    Set oTxtRng = oShp.Table.Rows(iRow).Cells
> > (iCol).Shape.TextFrame.TextRange
> >    Set oTmpRng = oTxtRng.Replace(FindWhat:=sSearchFor, _
> >     Replacewhat:=sReplaceWith, WholeWords:=False)
> >    Do While Not oTmpRng Is Nothing
> >     Set oTmpRng = oTxtRng.Replace(FindWhat:=sSearchFor, _
> >      Replacewhat:=sReplaceWith, _
> >      After:=oTmpRng.Start + oTmpRng.Length, _
> >      WholeWords:=False)
> >     Call SubScriptMe(oTxtRng, sReplaceWith)
> >    Loop
> >   Next
> >  Next
>
> > Case msoGroup
> >     For iCntr = 1 To oShp.GroupItems.Count
> >         Call SearchReplace(oShp.GroupItems(iCntr), sSearchFor,
> > sReplaceWith)
> >     Next iCntr
>
> > Case 21
> >     For iCntr = 1 To oShp.Diagram.Nodes.Count
> >         Call SearchReplace(oShp.Diagram.Nodes(iCntr).TextShape,
> > sSearchFor, sReplaceWith)
> >     Next iCntr
>
> > Case Else
> >     If oShp.HasTextFrame Then
> >         If oShp.TextFrame.HasText Then
> >             Set oTxtRng = oShp.TextFrame.TextRange
> >             Set oTmpRng = oTxtRng.Replace(FindWhat:=sSearchFor, _
> >              Replacewhat:=sReplaceWith, WholeWords:=False)
> >             Do While Not oTmpRng Is Nothing
> >              Set oTmpRng = oTxtRng.Replace(FindWhat:=sSearchFor, _
> >               Replacewhat:=sReplaceWith, _
> >               After:=oTmpRng.Start + oTmpRng.Length, _
> >               WholeWords:=False)
> >             Loop
> >             Call SubScriptMe(oTxtRng, sReplaceWith)
> >         End If
> >     End If
>
> > End Select
> > End Sub
>
> > Sub SubScriptMe(oTxtRng As TextRange, sReplaceWith As String)
> > Dim iPos As Long
> > iPos = InStr(oTxtRng, sReplaceWith)
> > Do While iPos > 0
> >  oTxtRng.Characters(iPos, 1).Font.SuperScript = True
> >  iPos = InStr(iPos + 1, oTxtRng, sReplaceWith)
> > Loop
> > End Sub
>
> ==============================
> PPT Frequently Asked Questions[URL="http://www.pptfaq.com/"]http://www.pptfaq.com/[/URL]
>
> PPTools add-ins for PowerPoint[URL="http://www.pptools.com/"]http://www.pptools.com/[/URL]
 >> Stay informed about: VBA - How to subscript? 
Back to top
Login to vote
Steve Rindsberg

External


Since: Nov 8, 2008
Posts: 108



(Msg. 4) Posted: Mon Nov 23, 2009 7:58 pm
Post subject: Re: VBA - How to subscript?
Archived from groups: per prev. post (more info?)

In article wrote:
> > Instead of iterating through all of the characters in the range, try
> > something like:
> >
> > For x = 1 to oTxtRng.Paragraphs.Count
> > Set oTmpRange = oTxtRng.Paragraphs(x)
> >
> > ' then work your magic on oTmpRng
> >
> > Next
> >
> > In article <80743adb-7716-47de-bcb2-
> >
> >
> >
> > 6ddb46fc3....Remove.TakeThisOut@d10g2000yqh.googlegroups.com>, Mel wrote:
> > > I'm replacing a character with another and then subscripting that new
> > > character. My code seems to work fine except when the object has
> > > multiple paragraphs. The last routine below (SubScriptMe) is called to
> > > subscript, but with multiple paragraphs it's counting the paragraph
> > > marker and screwing up the count to subscript the correct character.
> > > <argh!>
> >
> > > Is there a better way to accomplish this? Or is there a way to work
> > > around multiple paragraphs.
> >
> > > Thanks,
> > > Melina
> > > (code below)
> >
> > > Sub SearchReplaceSubscript()
> > > Dim oSld As Slide
> > > Dim oShp As Shape
> > > Dim sSearchFor As String
> > > Dim sReplaceWith As String
> > > sSearchFor = ChrW$(8482)
> > > sReplaceWith = ChrW$(9674)
> >
> > > For Each oSld In ActivePresentation.Slides
> > > For Each oShp In oSld.Shapes
> > > Call SearchReplace(oShp, sSearchFor, sReplaceWith)
> > > Next oShp
> > > Next oSld
> > > End Sub
> >
> > > Sub SearchReplace(oShp As Object, sSearchFor As String, sReplaceWith
> > > As String)
> > > Dim oTxtRng As TextRange
> > > Dim oTmpRng As TextRange
> > > Dim iCntr As Integer
> > > Dim iRow As Integer
> > > Dim iCol As Integer
> > > Dim oShpTmp As Shape
> >
> > > On Error Resume Next
> > > Select Case oShp.Type
> >
> > > Case 19
> > > For iRow = 1 To oShp.Table.Rows.Count
> > > For iCol = 1 To oShp.Table.Rows(iRow).Cells.Count
> > > Set oTxtRng = oShp.Table.Rows(iRow).Cells
> > > (iCol).Shape.TextFrame.TextRange
> > > Set oTmpRng = oTxtRng.Replace(FindWhat:=sSearchFor,
> > > Replacewhat:=sReplaceWith, WholeWords:=False)
> > > Do While Not oTmpRng Is Nothing
> > > Set oTmpRng = oTxtRng.Replace(FindWhat:=sSearchFor,
> > > Replacewhat:=sReplaceWith,
> > > After:=oTmpRng.Start + oTmpRng.Length,
> > > WholeWords:=False)
> > > Call SubScriptMe(oTxtRng, sReplaceWith)
> > > Loop
> > > Next
> > > Next
> >
> > > Case msoGroup
> > > For iCntr = 1 To oShp.GroupItems.Count
> > > Call SearchReplace(oShp.GroupItems(iCntr), sSearchFor,
> > > sReplaceWith)
> > > Next iCntr
> >
> > > Case 21
> > > For iCntr = 1 To oShp.Diagram.Nodes.Count
> > > Call SearchReplace(oShp.Diagram.Nodes(iCntr).TextShape,
> > > sSearchFor, sReplaceWith)
> > > Next iCntr
> >
> > > Case Else
> > > If oShp.HasTextFrame Then
> > > If oShp.TextFrame.HasText Then
> > > Set oTxtRng = oShp.TextFrame.TextRange
> > > Set oTmpRng = oTxtRng.Replace(FindWhat:=sSe
> archFor,
> > > Replacewhat:=sReplaceWith, WholeWords:=F
> alse)
> > > Do While Not oTmpRng Is Nothing
> > > Set oTmpRng = oTxtRng.Replace(FindWhat:=
> sSearchFor,
> > > Replacewhat:=sReplaceWith,
> > > After:=oTmpRng.Start + oTmpRng.Length,
> > > WholeWords:=False)
> > > Loop
> > > Call SubScriptMe(oTxtRng, sReplaceWith)
> > > End If
> > > End If
> >
> > > End Select
> > > End Sub
> >
> > > Sub SubScriptMe(oTxtRng As TextRange, sReplaceWith As String)
> > > Dim iPos As Long
> > > iPos = InStr(oTxtRng, sReplaceWith)
> > > Do While iPos > 0
> > > oTxtRng.Characters(iPos, 1).Font.SuperScript = True
> > > iPos = InStr(iPos + 1, oTxtRng, sReplaceWith)
> > > Loop
> > > End Sub
> >
> > ========================
> ======
> > PPT Frequently Asked Questions[URL="http://www.pptfaq.com/"]http://www.pptfaq.com/[/URL]
> >
> > PPTools add-ins for PowerPoint[URL="http://www.pptools.com/"]http://www.pptools.com/[/URL]


==============================
PPT Frequently Asked Questions
[URL="http://www.pptfaq.com/"]http://www.pptfaq.com/[/URL]

PPTools add-ins for PowerPoint
[URL="http://www.pptools.com/"]http://www.pptools.com/[/URL]
 >> Stay informed about: VBA - How to subscript? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
GIF Animations: PPT 2000 vs 2003 - I have a fairly complex animated GIF file which works fine when added to a presentation using PPT 2003. It also works fine when viewed with the 2007 PPT Viewer. When viewed with PPT 2000, or added to a presentation using 2000, it shows the first few..

Automatic Viewing - Is there a way that I can make my presentation continue to play without me clicking on it. Is there an auto view set up or something.

Side-by-side of different slide presentations - I have 4 slide presentations I need to place in a matrix of sorts that would show all four, or at least two, side-by-side. Can anyone help?

Populating a ListBox at runtime - Hi All, I've been using the following code to populate a ListBox. The trouble is it doesn't populate when double-clicking the PPS file to view the slideshow. I understand why it's not populating (since it has to be run while the ListBox is selected i...

help feature and Importing from Excel/Word - I am brand new to 2007 applications, but am familiar with 2003. I cannot seem to locate where the help option is in ppt 2007 and I needed to look up how to import a table from an Excel file I have into my presentation. If someone could please get me...
   Windows Help (Home) -> Microsoft Powerpoint All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]