Results 1 to 4 of 4

Thread: Line & Text Box in MS Word

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    66

    Line & Text Box in MS Word

    I am trying to us insert a line and a text box in a doc file using VBA. I am able to insert the same but I need help on the following :

    1. How to change the width of the line (Eg. Make it thin or fat)

    2. How to insert default text (eg. My name) inside the text box.

    I am enclosing the code for your reference.

    -----------
    Private Sub Command1_Click()
    Dim oW As Word.Application
    Dim oD As Word.Document

    Set oW = CreateObject("Word.Application")
    oW.Visible = True
    Set oD = oW.Documents.Add

    oD.Shapes.AddLine 50, 150, 150, 150
    oD.Shapes.AddTextbox msoTextOrientationHorizontal, 200, 100, 50, 100

    End Sub
    -----------

    Please help with a code.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Here you go!
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.  
    5.     Dim oW As Word.Application
    6.     Dim oD As Word.Document
    7.     Dim oS As Word.Shape
    8.    
    9.     Set oW = CreateObject("Word.Application")
    10.     oW.Visible = True
    11.     Set oD = oW.Documents.Add
    12.    
    13.     Set oS = oD.Shapes.AddLine(50, 150, 150, 150)
    14.     oS.Line.Style = msoLineSingle
    15.     oS.Line.Weight = 3
    16.     Set oS = Nothing
    17.     Set oS = oD.Shapes.AddTextbox(msoTextOrientationHorizontal, 200, 100, 50, 100)
    18.     oS.TextFrame.TextRange = "Default Text"
    19.     Set oS = Nothing
    20.    
    21. End Sub
    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    66

    Thumbs up

    Thankyou RobDog888

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    No prob.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width