S
Sridhar Pentlavalli via OfficeKB.com
Hi
I have a word document with some fields of a form in which data can be
entered.
I will be having one standard template (not another document... just
assigned to variables like text_1, text_2 ... in my macro. Please see below
example) in which I will be having some variables like Name, Age, Sex
etc... Get all the values of the varaible from the form fields... fill them
in variables and create a new docuemnt.
For Example, my Final Document should look like:
Name : Sridhar P
Age : 26
Sex : Male
So I will be having a form with three fields. I will read these three
values from the form in to Name, Age and Sex variables.
text_1 = "Name : " & Name
text_2 = " Age : " & Age
text_3 = " Sex : " & Sex
Now write these three lines in to a new docuemnt.
I have written a macro to meet my requirements. The Macro does the
following steps.
1. Read the values in the fiels of a form.
2. Fill the variables.
3. Create new instance of word by the command
Set appWD = CreateObject("Word.Application.10")
4. Create new document by the command
appWD.Documents.Add
5. Copy the text and paste in to this new word docuemnt by commands
Selection.Text = text_1
Selection.Copy
appWD.Selection.Paste
Selection.Text = text_2
Selection.Copy
appWD.Selection.Paste
Selection.Text = text_3
Selection.Copy
appWD.Selection.Paste
6. Save the new document by command
appWD.ActiveDocument.SaveAs "C:\Sri.doc"
7. Close and quit the word by commands
appWD.ActiveDocument.Close
appWD.Quit
The problems with my macro are
1. When I paste the text in the newly created docuemnt, it is getting
pasted in the new document and also it is being pasted in the original
document ( in which I have my form). How to avoid pasting in original
document.????
2. I need to paste these three text variables in three seperate lines. Now
they are comming in a single line. I mean "Enter" has to be somehow pasted
in the docuemnt. How to achieve this.?????
Can any body please help me.......
Thanks in advance....
Sridhar P
I have a word document with some fields of a form in which data can be
entered.
I will be having one standard template (not another document... just
assigned to variables like text_1, text_2 ... in my macro. Please see below
example) in which I will be having some variables like Name, Age, Sex
etc... Get all the values of the varaible from the form fields... fill them
in variables and create a new docuemnt.
For Example, my Final Document should look like:
Name : Sridhar P
Age : 26
Sex : Male
So I will be having a form with three fields. I will read these three
values from the form in to Name, Age and Sex variables.
text_1 = "Name : " & Name
text_2 = " Age : " & Age
text_3 = " Sex : " & Sex
Now write these three lines in to a new docuemnt.
I have written a macro to meet my requirements. The Macro does the
following steps.
1. Read the values in the fiels of a form.
2. Fill the variables.
3. Create new instance of word by the command
Set appWD = CreateObject("Word.Application.10")
4. Create new document by the command
appWD.Documents.Add
5. Copy the text and paste in to this new word docuemnt by commands
Selection.Text = text_1
Selection.Copy
appWD.Selection.Paste
Selection.Text = text_2
Selection.Copy
appWD.Selection.Paste
Selection.Text = text_3
Selection.Copy
appWD.Selection.Paste
6. Save the new document by command
appWD.ActiveDocument.SaveAs "C:\Sri.doc"
7. Close and quit the word by commands
appWD.ActiveDocument.Close
appWD.Quit
The problems with my macro are
1. When I paste the text in the newly created docuemnt, it is getting
pasted in the new document and also it is being pasted in the original
document ( in which I have my form). How to avoid pasting in original
document.????
2. I need to paste these three text variables in three seperate lines. Now
they are comming in a single line. I mean "Enter" has to be somehow pasted
in the docuemnt. How to achieve this.?????
Can any body please help me.......
Thanks in advance....
Sridhar P