add textbox while textbox is selected

L

larrysulky

Hi, All ---
This should be quick. I have a VBA command that works to create a
small textbox:

ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 0,
100, 50, Selection.Range).Select

But if a textbox is already the currently selected shape, then the
command fails with this message: "The specified range is not from the
correct document or story." Which doesn't surprise me. But I just
can't seem to reason out what I need to do to permit the textbox to be
created within the existing textbox, or, alternatively, to step
outside the existing textbox before creating the new textbox within
the main story.

Maybe it's just Saturday brain.... can anyone help?

TIA--
---larry
 
H

Helmut Weber

Hi,


kind of cascading textboxes:

Sub test9()
Dim lTmp As Long
For lTmp = 1 To 50 Step 10
ActiveDocument.Shapes.AddTextbox _
msoTextOrientationHorizontal, 100 + lTmp, lTmp, _
100, 50, Selection.Range
Next
End Sub

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

larrysulky

Hi,

kind of cascading textboxes:

Sub test9()
Dim lTmp As Long
For lTmp = 1 To 50 Step 10
ActiveDocument.Shapes.AddTextbox _
msoTextOrientationHorizontal, 100 + lTmp, lTmp, _
100, 50, Selection.Range
Next
End Sub

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Thanks, Helmut, but your macro has the same problem. If the cursor is
within a textbox when the macro is invoked, we get the same error
message. What's odd is that I can insert a textbox manually within the
textbox. But I can't figure out how to refer to the specific textbox
I'm in. The recorded macro goes like this:

Selection.ShapeRange.Select
ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal,
100, _
0, 50, 0).Select
Selection.ShapeRange.TextFrame.TextRange.Select
Selection.Collapse

I need to know how to set the anchor to the box that the cursor is in,
as a parameter following the dimension parameters. Something like
this:

ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal,
100, _
0, 50, 0, Selection.Range).Select

But Selection.Range is not right. Can you see through my blind spot?

Thanks --
--larry
 
H

Helmut Weber

Hi Larry,

I see. How about omitting anchor at all?

Cursor in the textbox:

Sub Test9A()
Dim x As Long
Dim y As Long
Dim w As Long
w = Selection.ShapeRange(1).Width - 50
T = Selection.ShapeRange(1).Top + 100
l = Selection.ShapeRange(1).Left + 100
h = Selection.ShapeRange(1).Height - 50


ActiveDocument.Shapes.AddTextbox _
msoTextOrientationHorizontal, l, T, w, h

End Sub

I don't know about a textbox in a textbox.
To me ist is not within the first textbox,
but positioned so that is appears to be within.
It is on another layer, so to speak.
And it is anchored to the paragraph the textbox
it was created from is anchored.

What could that be good for?

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

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