Visual Basic Help - MS Word

daveb1

New Member
Joined
Feb 19, 2008
Messages
14
Hi guys.

Looking for some help.

I am using macros/visual basic to create an adress generator for a letter in MS Word.

Basically an account number is input in a form box when Word opens, this searches a system which brings up a customers name and address and inputs it into the letter.

What i want to do is add another box onto the opening form, where a claim number will be input, i then want this claim number to be inserted into the letter.

The code for searching the name and address is very complicated and i'm struggling to work out how to get the claim number input from the form field. I think it will be really straight forward, but just don't know how to!

Any help will be much appreciated, if you need to see any code i am using then let me know.

Thanks.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi Dave,
this searches a system which brings up a customers name and address
What sort of a 'system' - an excel file, delimited text file, database?

As for adding the data to the Word file, that need be no more complicated that creating two bookmarks - one for the name & address area and one for the claim number, and inserting the form data at those points. A third bookmark could be used to output the account number.

Cheers
 
Upvote 0
Thanks for the reply.

Unfortunately my knowledge of visual basic is lacking and it doesn't make a great deal of sense!!

It searches an external datebase.

My userform shows two input boxes:

Customers Account Number:
Claim Number:

It uses the Account Number to search from.

All i want it to do is to take the number that is input into the claim number box and display that on the letter.

Can you help??
 
Upvote 0
Hi Dave,

You say your knowledge of visual basic is lacking. I trust you know at least enough to create and run a userform. If not, you'll need to spend some time learning the essentials; otherwise you're not going to get very far.

I can't really help you with retrieve the data from your database, but I can help with getting the retrieved data from your userform into the document.

To identify where the data are to go, you should create a set of bookmarks in your document - one for each piece of data (eg customer name, customer address (you may need multiple boomkarks for this - one for each line), claim number, account number).

Then, in the userform you're using to solicit the data, you'd use pass the bookmark name and its data to code like the following to populate the corresponding bookmark in the document:
Code:
Sub UpdateBookmark (BmkNm as string, BkTxt as string)
Dim BmkRng as Range
If ActiveDocument.Bookmarks.Exists(BmkNm) Then
  Set BmkRng = ActiveDocument.Bookmarks(BmkNm).Range
  BmkRng.Text = BkTxt
  ActiveDocument.Bookmarks.Add BmkNm, BmkRng
End if
Set BmkRng = Nothing
End sub
, where BmkNm is the name of the bookmark that you want to update and BkTxt is the data.

Cheers
 
Upvote 0

Forum statistics

Threads
1,225,364
Messages
6,184,533
Members
453,239
Latest member
dbenthu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top