Word 07 Prompt upon opening document and auto creating text fields

  • Thread starter GainesvilleWes via OfficeKB.com
  • Start date
G

GainesvilleWes via OfficeKB.com

Good morning,

I am trying to figure out how to create a simple macro that does the
following:

When opening the word document, a prompt will ask the user to enter a number,
then based on that number, it will create that many fields.

Example:

Question: How many Mortgages?:
The user enters "3"

The macro then creates these with text form fields after each colon.

Mortgage From: |__|
Mortgage To: |__|
Date: |__|
Principal: |__|

Mortgage From: |__|
Mortgage To: |__|
Date: |__|
Principal: |__|

Mortgage From: |__|
Mortgage To: |__|
Date: |__|
Principal: |__|

Any assistance would be greatly appreciated.
Thank you.
 
G

Graham Mayor

Assuming that's all you wish to do then at its most basic the following will
do that.

Dim sNum As Long
sNum = InputBox("How many mortgages?", "Mortgages")
For i = 1 To sNum
With Selection
.TypeText "Mortgage From: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeText "Mortgage To: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeText "Date: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeText "Principal: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeParagraph
End With
Next i
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

GainesvilleWes via OfficeKB.com

Thank you very much Graham. I will give this a shot.

Graham said:
Assuming that's all you wish to do then at its most basic the following will
do that.

Dim sNum As Long
sNum = InputBox("How many mortgages?", "Mortgages")
For i = 1 To sNum
With Selection
.TypeText "Mortgage From: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeText "Mortgage To: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeText "Date: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeText "Principal: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeParagraph
End With
Next i
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
Good morning,
[quoted text clipped - 28 lines]
Any assistance would be greatly appreciated.
Thank you.
 
G

GainesvilleWes via OfficeKB.com

Sorry to bother you again Graham, but i have one more question.

At the top of the word doc. there is already some fields for the user to fill
in and the mortgage information goes further down on the report. How can i
specify where on the word doc. i want the generated Mortgage From, Mortgage
To, etc to appear?

Graham said:
Assuming that's all you wish to do then at its most basic the following will
do that.

Dim sNum As Long
sNum = InputBox("How many mortgages?", "Mortgages")
For i = 1 To sNum
With Selection
.TypeText "Mortgage From: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeText "Mortgage To: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeText "Date: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeText "Principal: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeParagraph
End With
Next i
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
Good morning,
[quoted text clipped - 28 lines]
Any assistance would be greatly appreciated.
Thank you.
 
G

Graham Mayor

I would help to see the document - can you send a copy to the link on the
home page of my web site? Can you indicate where exactly you want the
multiple copies inserting?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Sorry to bother you again Graham, but i have one more question.

At the top of the word doc. there is already some fields for the user
to fill in and the mortgage information goes further down on the
report. How can i specify where on the word doc. i want the generated
Mortgage From, Mortgage To, etc to appear?

Graham said:
Assuming that's all you wish to do then at its most basic the
following will do that.

Dim sNum As Long
sNum = InputBox("How many mortgages?", "Mortgages")
For i = 1 To sNum
With Selection
.TypeText "Mortgage From: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeText "Mortgage To: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeText "Date: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeText "Principal: "
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.TypeParagraph
.TypeParagraph
End With
Next i
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
Good morning,
[quoted text clipped - 28 lines]
Any assistance would be greatly appreciated.
Thank you.
 
G

GainesvilleWes via OfficeKB.com

Email Sent. Nice web page btw. Liked the cat pics. :)

Graham said:
I would help to see the document - can you send a copy to the link on the
home page of my web site? Can you indicate where exactly you want the
multiple copies inserting?
Sorry to bother you again Graham, but i have one more question.
[quoted text clipped - 37 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top