Macro for Word

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Experts,
I am designing a form in word 2003. Want to make a macro which does the
following function. This is for a report generated after I finish the
Instrument installation.
At one customer site, we will install one to many instruments.
I used the Form tool, to put the drop down menu for Quantity of instruments.
Macro i need should be able to create new text fields for entering the
serial number of instruments depending on the quantity of instruments
selected above.
eg: If I select Instrument A is of Qty 2, then 2 text fields should pop up
below in the word document to enter the serial number of that.
Later I should be able to save the document and print out.
Can some one help me with this or if there is any other way, kindly help
suggest.
Thanks and Regards
VSK
 
Yeah, sort of.

If you have your dropdown and then at least one text field (assuming
you will always have at least one SN to enter) then you could add a
bookmark "AddFields" after the text field and run this code on exit
from the DropDown:

Sub AddFields()
ActiveDocument.Unprotect
Dim oFF As FormFields
Set oFF = ActiveDocument.FormFields
Dim i As Long
For i = 2 To oFF("DropDown1").DropDown.Value
ActiveDocument.Bookmarks("AddFields").Range.InsertAfter " "
oFF.Add ActiveDocument.Bookmarks("AddFields").Range,
wdFieldFormTextInput
Next i
ActiveDocument.Protect wdAllowOnlyFormFields, True
End Sub
 
Hi Sir,

Thankyou very much for your valuable feedback. I am totally new to the
macros and tried to copy the commands in the macro and execute it.

first I opened the word, created a List box (bookmark as dropdown1) using
formfield. then created a textbox with bookmark as text 1. Then below the
text1 i inserted the Bookmark "Addfields" using the Insert command.

After this I protected the document and selected the number 3. When I exited
nothing happened. But when I went and click the Text1, another text box was
created right below text 1. When I click the Text 2, another text box was
created. In short, it was creating more text box rather than required
everytime i click it.

Can you please give your expert advice.

thanks and regards
VSK
 
You shouldn't be using the control toolbox to enter activeX controls. Use
the View>Toolbars and open the Forms toolbar. Insert a dropdown field (it
will automatically be called dropdown1 by defualt.

Add your numbers (e.g., 1, 2, 3, 4, 5, etc).

Insert the macro text I provided you in the VBA project for the document.

Back in the document, double click the formfield and set AddFields macro to
run on exit. Insert a text field after the dropdown, insert a bookmark
named "AddField" after the text field.

Protect the document and Bob's your uncle.
 
Hi Sir,

I didnt use a control toolbox, instead i said the same way as u have
mentioned. But as I said, before, after I select and exit the dropdown menu,
nothing pops up. But then when I click the text 1 , the second text box pops
up. Even if the selection in the drop down box is 3, the text box creation
continues. This is what confuses me.

Thanks and regarrds
VSK
 
Send me your document and I will look at it this evening if I get a
chance.

(e-mail address removed) (delete the CAPS)
 
Back
Top