Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Jan 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to insert data in Word Template using userform

    hi to all

    am new to VBA in word, i had create user-form in word for data inserting. when i submit the data, the data is not overwriting , due to this my word alignment changed. how to over come this?

    Here is my code
    Code:
    Private Sub CommandButton1_Click()
    Dim Name As Range
    Set Name = ActiveDocument.Bookmarks("GreetName").Range
    Name.Text = Me.Gname.Value
    
    Dim Address As Range
    Set Address = ActiveDocument.Bookmarks("ToAdd").Range
    Address.Text = Me.Taddress.Value
    
    Dim dt As Range
    Set dt = ActiveDocument.Bookmarks("Date").Range
    dt.Text = Me.TDate.Value
    
    Dim Ref As Range
    Set Ref = ActiveDocument.Bookmarks("Ref").Range
    Ref.Text = Me.TRef.Value
    
    Dim Posi As Range
    Set Posi = ActiveDocument.Bookmarks("Position").Range
    Posi.Text = Me.CPosition.Value
    
    Dim CTCF As Range
    Set CTCF = ActiveDocument.Bookmarks("CTCfig").Range
    CTCF.Text = Me.CTCFig.Value
    
    Dim CTCW As Range
    Set CTCW = ActiveDocument.Bookmarks("CTCText").Range
    CTCW.Text = Me.CTCWord.Value
    
    End Sub
    Thanks for advance
    Last edited by RetiredGeek; 2014-01-09 at 04:47.

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    5,783
    Thanks
    184
    Thanked 698 Times in 636 Posts
    Sateesh,

    Welcome to the Lounge as a new poster.

    You can control the Overtype/Insert option via:
    Options.Overtype = True (Turn On - Overtype) or False (Turn Off - Insert)

    In your code I would advise:
    Code:
    Private Sub CommandButton1_Click()
    
           Dim bCurrentOTMode  as Boolean
    
           bCurrentOTMode = Options.Overtype
           Options.Overtype = False   'Turn Insert On
    
           '*** Note: I took the liberty of simplifying the code here ***
            With ActiveDocument
                    .Bookmarks("GreetName").Range.Text = Me.Gname.Value
                    .Bookmarks("ToAdd").Range.Text = Me.Taddress.Value
                    .Bookmarks("Date").RangeText = Me.TDate.Value
                    .Bookmarks("Ref").RangeText = Me.TRef.Value
                    .Bookmarks("Position").Rangei.Text = Me.CPosition.Value
                    .Bookmarks("CTCfig").Range.Text = Me.CTCFig.Value
                    .Bookmarks("CTCText").Range.Text = Me.CTCWord.Value
            End With   'ActiveDocument
    
            Options.Overtype = bCurrentOTMode  'Return to original mode
    
    End Sub
    HTH
    Last edited by RetiredGeek; 2014-01-09 at 05:19.
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


Posting Permissions

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