A Microsoft Word forum. Microsoft Office Word Forum - WordBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Microsoft Office Word Forum - WordBanter forum » Microsoft Word Newsgroups » Microsoft Word Help
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Text box macro



 
 
Thread Tools Display Modes
  #1  
Old May 29th 19, 05:53 PM
GrahamSwindon GrahamSwindon is offline
Junior Member
 
First recorded activity by WordBanter: May 2019
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.
Ads
  #2  
Old June 3rd 19, 09:15 PM
kilroyscarnival kilroyscarnival is offline
Junior Member
 
First recorded activity by WordBanter: Jun 2019
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
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
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:46 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright ©2004-2019 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.