Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-31-2017, 06:52 AM
dpashley dpashley is offline Create text box in VBA and style content Windows 10 Create text box in VBA and style content Office 2010 32bit
Novice
Create text box in VBA and style content
 
Join Date: Sep 2016
Posts: 6
dpashley is on a distinguished road
Default 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:
  • Insert a text box to my existing Word document
  • Add some text
  • Set font, size and alignment
  • Set border style of the text box
  • Set position
Any help would be most appreciated!


Thanks,


Dan
Reply With Quote
  #2  
Old 07-31-2017, 12:41 PM
gmaxey gmaxey is offline Create text box in VBA and style content Windows 7 32bit Create text box in VBA and style content Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,438
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 08-01-2017, 01:40 AM
dpashley dpashley is offline Create text box in VBA and style content Windows 10 Create text box in VBA and style content Office 2010 32bit
Novice
Create text box in VBA and style content
 
Join Date: Sep 2016
Posts: 6
dpashley is on a distinguished road
Default

Great stuff! Much appreciated!
Reply With Quote
Reply

Tags
style, textbox, vba in microsoft word



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create text box in VBA and style content 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
Create text box in VBA and style content 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

Other Forums: Access Forums

All times are GMT -7. The time now is 08:51 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft