+ Reply to Thread
Results 1 to 7 of 7

Macro to create Text Box

  1. #1
    Registered User
    Join Date
    01-28-2009
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2003
    Posts
    18

    Macro to create Text Box

    I want to create a macro that will allow me to create a Text box with the letters TB in red font in the text box. I also want the text box to be created with no fill and no lines visible just the initals.

    Also is there a way to hide the macro creating the text box so that when you run the macro the initals appear without showing the text box and changes being made to it?

  2. #2
    Registered User
    Join Date
    01-28-2009
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Macro to create Text Box

    Here is the coding I have so far and the text box is not transparent and the macro also shows the creation of the text box.

    Sub TB_Initials()
    '
    ' TB_Initials Macro
    '
    '
    ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 247.05, _
    351.2, 72#, 72#).Select
    Selection.ShapeRange.TextFrame.TextRange.Select
    Selection.Collapse
    Selection.TypeText Text:="TB"
    Selection.ShapeRange.Select
    Selection.ShapeRange.Fill.Visible = msoFalse
    Selection.ShapeRange.Fill.Solid
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.Weight = 0.75
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.Line.Style = msoLineSingle
    Selection.ShapeRange.Line.Transparency = 0#
    Selection.ShapeRange.Line.Visible = msoFalse
    Selection.ShapeRange.LockAspectRatio = msoFalse
    Selection.ShapeRange.Height = 72#
    Selection.ShapeRange.Width = 72#
    Selection.ShapeRange.Left = 246.95
    Selection.ShapeRange.Top = 351.35
    Selection.ShapeRange.TextFrame.MarginLeft = 7.2
    Selection.ShapeRange.TextFrame.MarginRight = 7.2
    Selection.ShapeRange.TextFrame.MarginTop = 3.6
    Selection.ShapeRange.TextFrame.MarginBottom = 3.6
    Selection.ShapeRange.RelativeHorizontalPosition = _
    wdRelativeHorizontalPositionColumn
    Selection.ShapeRange.RelativeVerticalPosition = _
    wdRelativeVerticalPositionParagraph
    Selection.ShapeRange.Left = InchesToPoints(3.43)
    Selection.ShapeRange.Top = InchesToPoints(4.88)
    Selection.ShapeRange.LockAnchor = False
    Selection.ShapeRange.LayoutInCell = True
    Selection.ShapeRange.WrapFormat.AllowOverlap = True
    Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
    Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
    Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
    Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
    Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
    Selection.ShapeRange.WrapFormat.Type = 3
    Selection.ShapeRange.ZOrder 4
    Selection.ShapeRange.TextFrame.AutoSize = False
    Selection.ShapeRange.TextFrame.WordWrap = True
    Selection.Font.Color = wdColorRed
    Selection.ShapeRange.ScaleWidth 0.42, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleHeight 0.33, msoFalse, msoScaleFromTopLeft
    ActiveDocument.Select
    End Sub

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro to create Text Box

    Try creating it with the macro recorder running

    http://www.excel-it.com/record_macro.htm
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro to create Text Box

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  5. #5
    Registered User
    Join Date
    01-28-2009
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Macro to create Text Box

    Here is the code posted properly.

    Please Login or Register  to view this content.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro to create Text Box

    Hello byrdsongdl,

    This is not an Excel macro but a Word macro. They both use VBA, however, the code is not identical. We do have a forum for Word programming. I am moving your post to the correct forum.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Registered User
    Join Date
    02-19-2009
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    1

    Post Re: Macro to create Text Box

    Hi All

    I'm completely new to Word programming . I have been trying to create a way to make a coloured text box appear around highlighted text. So if I highlight a paragraph in a word document it will be put into a text box in its original position in the document.

    I have managed to use the code in the messages above, but can't change it to use highlighted text in situ.

    Can anyone help please?

    thanks
    scube

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1