Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
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
![]() |
|||
|
|||
![]() Quote:
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 | |
|
|
![]() |
||||
Thread | Forum | |||
Text Box Macro | New Users | |||
Macro for TEXT Box to Plain Text Conversion? | Microsoft Word Help | |||
Macro only selected text | Microsoft Word Help | |||
Macro to find text, then delete entire line containing the text? | Microsoft Word Help | |||
Selecting Text in Macro | Microsoft Word Help |