#1   Report Post  
GrahamSwindon GrahamSwindon is offline
Junior Member
 
Posts: 0
Default Text box macro

Can someone point me towards code that will create a text box and place the insertion point inside the box? Iím a novice at vb. I can record a macro that creates the box but the insertion point remains outside.
  #2   Report Post  
kilroyscarnival kilroyscarnival is offline
Junior Member
 
Posts: 1
Default

Quote:
Originally Posted by GrahamSwindon View Post
Can someone point me towards code that will create a text box and place the insertion point inside the box? Iím a novice at vb. I can record a macro that creates the box but the insertion point remains outside.
I gave it a try... it seems for me when it created a text box, the dummy text in the box was already highlighted, which meant I didn't have to select it, could just hit paste.

Highlight the text you want to insert in a text box then run the macro. This includes a command taking you to the top of the paragraph that text is in before inserting your text box. By the way you can't mouse click to do that while recording a macro; the keystrokes are CONTROL + UP_ARROW keys.

Sub Macro1()
'
' Macro1 Macro
'
'
Selection.Copy
Selection.MoveUp Unit:=wdParagraph, Count:=1
ActiveDocument.Shapes.Range(Array("Text Box 2")).Select
Application.Templates( _
"C:\Users\[me]\AppData\Roaming\Microsoft\Document Building Blocks\1033\14\Built-In Building Blocks.dotx" _
).BuildingBlockEntries(" Simple Text Box").Insert Whe=Selection.Range, _
RichText:=True
Selection.PasteAndFormat (wdFormatOriginalFormatting)
End Sub


What I use is not properly a text box, but a single cell table, which is what some of our engineering documents use as a callout text box to highlight significant text in the documents.

I needed to make sure my cursor would move to the top of the current paragraph before creating the text box. That's what the MoveLeft, MoveUp lines are about. I also had the table "text box" saved in my building blocks formatted the way I generally need it (shading, borders, etc.) So I inserted it from the Building Block path. Then I had to select the text box using "GoTo" the previous table, since my cursor was below the newly created table. Then I had to use Extend to get it to select the entire paragraph of text in the dummy table (it hadn't occurred to me, I could have probably saved it to Building Blocks with no text in it.)

Sub mktextbox()
'
' mktextbox Macro
'
'
Selection.Copy
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdParagraph, Count:=1
Application.Templates( _
"C:\Users\{me]\AppData\Roaming\Microsoft\Document Building Blocks\1033\14\Building Blocks.dotx" _
).BuildingBlockEntries("TextBox").Insert Whe=Selection.Range, RichText _
:=True
Selection.GoTo What:=wdGoToTable, Which:=wdGoToPrevious, Count:=1, Name:= _
""

With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Extend
Selection.Extend
Selection.Extend
Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:= _
wdFloatOverText, DisplayAsIcon:=False
Selection.Extend
Selection.Extend
Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
End Sub
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Text Box Macro akkrug New Users 8 December 12th 07 08:34 PM
Macro for TEXT Box to Plain Text Conversion? binar Microsoft Word Help 1 July 30th 07 10:36 PM
Macro only selected text Greg In Atl Microsoft Word Help 2 April 26th 07 08:30 PM
Macro to find text, then delete entire line containing the text? Tailings Microsoft Word Help 2 September 16th 06 03:52 AM
Selecting Text in Macro Jihrke Microsoft Word Help 4 October 14th 05 05:41 PM


All times are GMT +1. The time now is 03:45 PM.

Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright ©2004-2023 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"