SHAPE QUESTION

L

LEU

I have a macro that creates shapes in my documents. The macro gives each
shape its own name (Example: vln1, vln2 and so on). Is there a way to write a
macro so I do not have to manually scroll down through the document and find
each one. I need it to find the first one, stop let me look at the text where
it is located and then when I’m ready go to the next one.

LEU
 
H

Helmut Weber

Hi LEU,

you might find a modeless userform helpful.

' module1 e.g.
' -----------------------
Sub Testx0()
UserForm1.Show vbModeless
End Sub

' -------------------------------------------

' userform1
Dim lCnt As Long ' public for userform
' -------------------------------------------
Private Sub CommandButton1_Click()
lCnt = lCnt + 1
ActiveDocument.Shapes(lCnt).Select
ActiveWindow.ScrollIntoView Selection.Range, True
End Sub

Private Sub UserForm_Initialize()
lCnt = 0
End Sub

I leave the handling of the error,
which occurs if lCnt becomes greater than
the number of shapes, to you.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
L

LEU

Hi Helmut,

When I click on my commandbutton it goes thru and finds all of my vln's but
it it keeps going and finds all the other shapes too. This is what I have:

Private Sub CommandButton1_Click()
On Error GoTo endthis
vln = vln + 1
ActiveDocument.Shapes(vln).Select
ActiveWindow.ScrollIntoView Selection.Range, True
endthis:
End Sub

Also is there a way to use wild card charters in this kind of search? I have
another shapes I call aPCN, bPCN and cPCN. I tried this but get an error:

Private Sub CommandButton1_Click()
On Error GoTo endthis
PCN = ?PCN + 1
ActiveDocument.Shapes(vln).Select
ActiveWindow.ScrollIntoView Selection.Range, True
endthis:
End Sub
 
R

Russ

LEU,
Use your same error code

lCnt is a number used for incrementing through all the shapes.

You could use a loop that tests the shape name
Public lCnt As Long ' public for userform
lCnt = lCnt + 1
Do While True
If ActiveDocument.Shapes( lCnt).Name Like "[a-z]PCN" Or _
ActiveDocument.Shapes( lCnt).Name Like "vln#" Or _
ActiveDocument.Shapes( lCnt).Name Like " vln##" then
ActiveDocument.Shapes( lCnt).Select
ActiveWindow.ScrollIntoView Selection.Range, True
Exit Sub
Else
lCnt = lCnt + 1
End If
Loop
 
L

LEU

Helmut & Russ,

That did the trick. Thank you again for all your help.

LEU



Russ said:
LEU,
Use your same error code

lCnt is a number used for incrementing through all the shapes.

You could use a loop that tests the shape name
Public lCnt As Long ' public for userform
lCnt = lCnt + 1
Do While True
If ActiveDocument.Shapes( lCnt).Name Like "[a-z]PCN" Or _
ActiveDocument.Shapes( lCnt).Name Like "vln#" Or _
ActiveDocument.Shapes( lCnt).Name Like " vln##" then
ActiveDocument.Shapes( lCnt).Select
ActiveWindow.ScrollIntoView Selection.Range, True
Exit Sub
Else
lCnt = lCnt + 1
End If
Loop
Hi Helmut,

When I click on my commandbutton it goes thru and finds all of my vln's but
it it keeps going and finds all the other shapes too. This is what I have:

Private Sub CommandButton1_Click()
On Error GoTo endthis
vln = vln + 1
ActiveDocument.Shapes(vln).Select
ActiveWindow.ScrollIntoView Selection.Range, True
endthis:
End Sub

Also is there a way to use wild card charters in this kind of search? I have
another shapes I call aPCN, bPCN and cPCN. I tried this but get an error:

Private Sub CommandButton1_Click()
On Error GoTo endthis
PCN = ?PCN + 1
ActiveDocument.Shapes(vln).Select
ActiveWindow.ScrollIntoView Selection.Range, True
endthis:
End Sub
 

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