#1
|
|||
|
|||
Create text box in VBA and style content
Hi,
I am trying to use VBA to create a series of text boxes in a Word document automatically and then set the style of them. What I need to be able to do is:
Thanks, Dan |
#2
|
|||
|
|||
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 7/31/2017 Dim oShp_TB As Shape '1. Set oShp_TB = ActiveDocument.Shapes.AddTextbox( _ Orientation:=msoTextOrientationHorizontal, _ Left:=50, Top:=50, Width:=100, Height:=100) With oShp_TB With .TextFrame.TextRange '2. .Text = "This is some text" '3. .Font.Name = "Calibri" .Font.Size = 8 .Font.ColorIndex = wdBlue .ParagraphFormat.Alignment = wdAlignParagraphCenter 'Or use a defined style '.Style = "My TextBox Style" End With '4. With .Line .Weight = 2 .ForeColor = wdColorRed End With '5. .Left = 200 .Top = 300 End With lbl_Exit: Exit Sub End Sub |
#3
|
|||
|
|||
Great stuff! Much appreciated!
|
Tags |
style, textbox, vba in microsoft word |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Rich Text Content Contol retain Style Setting when whole document is changed | ciresuark | Word | 1 | 02-22-2016 06:25 PM |
Macro to create a title in the Header when a certain text style is used (such as Heading 1) | Lonesy | Word VBA | 1 | 06-03-2015 03:57 AM |
I create a new style but it fails to appear in Quick Style list | veronius | Word | 6 | 06-18-2013 06:29 PM |
Matching text style to drawing object style | notarichman | PowerPoint | 0 | 03-07-2011 11:34 AM |
How to create macro to paste text after style? | Srivas | Word | 0 | 03-16-2010 05:28 AM |