A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Powerpoint, Publisher and Visio » Powerpoint
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

VBA - How to subscript?



 
 
Thread Tools Display Modes
  #1  
Old November 22nd, 2009, 11:11 PM posted to microsoft.public.powerpoint
Mel
external usenet poster
 
Posts: 89
Default VBA - How to subscript?

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
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:22 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.