Step through VBA code(F8) good, run(F5) bad

E

eldon.l.lehman

The attributes of the shapes created by the code are made properties of
the shapes on the slide, but they do not show on the slide as having
taken effect by the run. Stepping through one line at a time not only
establishes the attributes, but reflectes them on the slide. Any
thoughts to the error in the programming?
Thank you,
Eldon
--------Begin code----------
Option Explicit

Public Sub fmtEq()

' Rectangle 2 of slide 1 contains the formula " Na2SO4",
' with a space preceding the N and no quotation marks
Dim lft As Double 'left position of textbox
Dim wth As Double 'width of textbox
Dim i As Integer 'increment of characters selected to format
Dim shpName As String 'name of text box shape
Dim prevShp As String 'name of text box shape on a loop prior to
current one
Dim txtRng As TextRange 'range of text to be formatted
Dim chRng As TextRange 'range of individual character to currently
format
'setting text range, initializing variables
Set txtRng = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange
lft = 0
wth = 24
shpName = "Coef"
prevShp = "Rectangle 2"
For i = 1 To txtRng.Length
Set chRng = txtRng.Characters(i, 1)
Select Case Asc(chRng)
Case 32 'space
shpName = "Coef" & i
Case 48 To 57 'numbers
If Right(prevShp, 4) <> "Coef" Then shpName = "Sub" & i
Case 65 To 90 'Upper case
shpName = chRng
Case 97 To 120 'Lower case
shpName = chRng
End Select
With ActivePresentation.Slides(1)
.Shapes.AddShape(msoShapeRectangle, 0, 0, wth, 24) _
.Name = shpName
With .Shapes(shpName)
With .TextFrame
If chRng = " " Then
.TextRange = "1" 'Makes
coeficient start at 1
Else: .TextRange = chRng 'fills shape
with character if it is not a space
End If
.MarginLeft = 0 'set margins of
textframe
.MarginRight = 0
.AutoSize = ppAutoSizeShapeToFitText 'autosizes
shape to text contents
.TextRange.Font.Color.RGB = RGB(255, 255, 255)
End With
.Left = lft + wth 'moves shape to
position
.Top = 0
.Height = 24
.Fill.Visible = msoFalse
End With
'
If Left(shpName, 3) = "Sub" Then
..Shapes(shpName).TextFrame.TextRange.Font.Subscript = msoTrue
'sets variables for positioning next shape
lft = .Shapes(shpName).Left
wth = .Shapes(shpName).Width
prevShp = .Shapes(shpName).Name
End With
'' SlideShowWindows(1).View.GotoSlide 1
Next i
End Sub
---------End Code------------
 
S

Steve Rindsberg

The attributes of the shapes created by the code are made properties of
the shapes on the slide, but they do not show on the slide as having
taken effect by the run. Stepping through one line at a time not only
establishes the attributes, but reflectes them on the slide. Any
thoughts to the error in the programming?

Are you seeing the problem when running a slide show? If so, modify the
(currently commented out) line that does a GoToSlide. Have it go to the same
slide you're currently working with ... that forces PPT to refresh the display.

If that's not it,
 
E

eldon.l.lehman

Steve said:
Are you seeing the problem when running a slide show? If so, modify the
(currently commented out) line that does a GoToSlide. Have it go to the same
slide you're currently working with ... that forces PPT to refresh the display.

If that's not it,


-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Steve,
Thanks for giving it a go. Yes, it is happening in slide show mode with
the line not commented out and in the edit mode when using F5 to run
the Sub. The only time that it displays correctly is the stepping, F8.
I have even tried to DoEvents with a loop, but same results.
Eldon
 
E

eldon.l.lehman

Me again,
Steve, you were right about the '' SlideShowWindows(1).View.GotoSlide
1. I found that it was not in the right spot in the code for what I was
trying to do. Apparently it is a "what have you done for me lately"
temperament setting in the slideshow.
Thank you again for pointing out the culprit.
Eldon
 
E

eldon.l.lehman

Steve,
Thanks for giving it a go. Yes, it is happening in slide show mode with
the line not commented out and in the edit mode when using F5 to run
the Sub. The only time that it displays correctly is the stepping, F8.
I have even tried to DoEvents with a loop, but same results.
Eldon

Me again, error in the last posting.
Steve, you were right about the ''SlideShowWindows(1).View.GotoSlide 1.
I had placed it in the wrong area of the code. Apparently it needs to
get the command earlier when in slide show. Thanks again for pointing
out the culprit.
Eldon
 
S

Steve Rindsberg

Me again,
Steve, you were right about the '' SlideShowWindows(1).View.GotoSlide
1. I found that it was not in the right spot in the code for what I was
trying to do. Apparently it is a "what have you done for me lately"
temperament setting in the slideshow.

Yep. It doesn't automatically refresh the display with every change you make in
code. A good thing, when you think about it ... otherwise the show would be
dancing around like a maniac if you had many changes to make in one routine.
Thank you again for pointing out the culprit.

My pleasure ... and thanks for letting me know it all worked out.
 

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