943,441 Members | Top Members by Rank

Ad:
Aug 6th, 2003
0

I need help using VBA for Word Macros

Expand Post »
I have a document that needs to be filled out. To help the user input all the correct information that goes on the form, I built a user form. On enter, the information gets transferred to the form. To accomplish this I use this statements like the ones below:

ActiveDocument.Bookmarks("NAME").range.InsertBefore txtName
ActiveDocument.Bookmarks("ADDRESS").range.InsertBefore txtAddress

This works great because I have separate bookmarks for Name and Address. But, what if I just have one bookmarks called "DATA":

ActiveDocument.Bookmarks("DATA").range.InsertBefore txtNetWeight _
& vbTab & txtCostPerLbs & vbCrLf

After this gets put on the document, I ask the users if he needs to input data again. If he clicks on Yes, then:

ActiveDocument.Bookmarks("DATA").range.InsertBefore txtNetWeight _
& vbTab & txtCostPerLbs & vbCrLf

BUT, here's the problem. I need the second set of data to be inserted below the first line that is already on the document. What happens instead is that it gets inserted above the line that is already on the document.

Any ideas? :roll:
Similar Threads
Reputation Points: 12
Solved Threads: 0
Newbie Poster
I_Byte is offline Offline
22 posts
since Jul 2003
Aug 6th, 2003
0

Re: I need help using VBA for Word Macros

Well, I'm a VB.NET developer, and I don't really know much about VBA with MS Word, but, why not try creating a new bookmark at the end of your inserted portion, and then insert at that new bookmark?

You could then have an unlimited amount of inserts without a problem.
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Aug 8th, 2003
0

VBA

Thanks for the reply. I actually received some help yesterday from a different source, Martin Green's Office Tips, and my problem is now solved. You were correct in your suggestion. Here's what Mr. Green suggested:

Dim DataRange As Range
Set DataRange = ActiveDocument.Bookmarks("Data").Range
If DataRange = "" Then
DataRange = "Some Text"
Else
DataRange = DataRange & " " & "More Text"
End If
ActiveDocument.Bookmarks.Add "Data", DataRange

Where I have written "Some Text" and "More Text" you can substitute with you textbox names. My example puts a space between the insertions. You could puta line break instead:

DataRange = DataRange & vbCrLf & "More Text"

I think that would work
Reputation Points: 12
Solved Threads: 0
Newbie Poster
I_Byte is offline Offline
22 posts
since Jul 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Windows NT / 2000 / XP Forum Timeline: New Hardware Causing Error
Next Thread in Windows NT / 2000 / XP Forum Timeline: How To Tweak Icon Sizes and so,Windows XP Startbar





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC