2014-01-09, 03:24 #1
- Join Date
- Jan 2014
- 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
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
Last edited by RetiredGeek; 2014-01-09 at 04:47.
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!
+ 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!
2014-01-09, 05:17 #2
- Join Date
- Mar 2004
- Manning, South Carolina
- Thanked 730 Times in 666 Posts
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:
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