PDA

View Full Version : Extend a Fill-in Form



JPDO
10-22-2004, 03:52 PM
Hello,
I try to fill-up a Word fill-in form from Excel.
I have to fill-in the information of the fields coming from 2 Excel Spreadsheets.
Only a few cell-values are to fill-in in the Word-document.
This works without problems.
But after filing-up the info from each Excel Spreadsheet i have to extend the fill-in form with a copy-paste-values (or if possible with the xls-spreadsheet object itself) of the WHOLE spreadsheet.
Each of the spreadsheets should begin on a new page.

So i tought to execute this in following steps:

1- Open Word-applic and the template
2- Paste text-info from spreadsheet1 in the template
Extend the template and insert the Whole spreadsheet1
3- Paste text-info from spreadsheet2 in the template
Extend the template and insert the whole spreadsheet2
4- Close and save the document

Unfortunately in Step 2 i have no error, but I can not find a new page with the text "Hello". What am i missing ?

Here goes my code
Public Sub RunMe()
Teller = 1 'Open Word - applic
ExcelWord (teller)
teller = 2 ' Treat Spreadsheet1
ExcelWord (teller)
teller = 3 ' Treat Spreadsheet2
ExcelWord (teller)
teller = 4 ' Close and save the whole thing
ExcelWord (teller)
End Sub

Public Sub ExcelWord(teller)
Dim WdApp As Word.Application
Dim WdDoc As Word.Document
Dim pagtel As Long

Select Case teller
Case 1 'Open Word-application
Set WdApp = CreateObject("Word.Application")
With WdApp
.Visible = True
.Documents.Add Template:="C:\DATA\word\Evaluation.dot", _
NewTemplate:=False, _
DocumentType:=0
With .ActiveDocument
ActiveDocument.FormFields("Text3").Result = "This is my text3"
ActiveDocument.FormFields("Text4").Result = "This is my text4"
End With
End With
Case 2 ' Updates from spreadsheet1
ActiveDocument.Unprotect
ActiveDocument.Paragraphs(ActiveDocument.Paragraphs.Count).Range.InsertPara graphAfter
ActiveDocument.Paragraphs(ActiveDocument.Paragraphs.Count).Range.Text = "Hello"
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=False
End Select
End Sub

TonyJollans
10-31-2004, 04:17 PM
Hi JPDO,

The only thing I can see wrong is your use of ActiveDocument which should be qualified with WdApp, in other words ..

With WdApp.ActiveDocument
.Unprotect
.Paragraphs(.Paragraphs.Count).Range.InsertParagraphAfter
.Paragraphs(.Paragraphs.Count).Range.Text = "Hello"
.Protect Type:=wdAllowOnlyFormFields, NoReset:=False
End With