Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

add textbox while textbox is selected

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
larrysulky@gmail.com - 21 Apr 2007 16:17 GMT
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
Helmut Weber - 21 Apr 2007 21:17 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

larrysulky@gmail.com - 22 Apr 2007 19:04 GMT
> Hi,
>
[quoted text clipped - 18 lines]
> 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
Helmut Weber - 22 Apr 2007 22:20 GMT
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?

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

larrysulky@gmail.com - 23 Apr 2007 01:23 GMT
> Hi Larry,
>
> I see. How about omitting anchor at all?

Aha! That works, Helmut! I knew I was having a brain cramp! :-)

Thank you ---

---larry
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.