I have a Word Template that uses form control textboxes (bookmarks).
I have them name txtCourseNum and txtCourseName.
When I type in the txtCourseNum, I want it to automatically populate the
txtCourseName. I have the CourseNum and CourseName in arrays, but I don't
know how to reference the textboxes to allow the data to move into it.
While I'm asking, is there a good ways to read the array data from and Excel
spreadsheet into the arrays. At this time, I'm forcing the data in with
assignment statements.
Thanks in advance to any help.
John
John Viall was telling us:
John Viall nous racontait que :
> I have a Word Template that uses form control textboxes (bookmarks).
>
[quoted text clipped - 4 lines]
> but I don't know how to reference the textboxes to allow the data to
> move into it.
ActiveDocument.Formfields("txtCourseNum").Result
But you might want to use a dropdown list instead, to make sure that only
acceptable ### are entered, or, you can trap erroneous entries and still use
a text field.
> While I'm asking, is there a good ways to read the array data from
> and Excel spreadsheet into the arrays. At this time, I'm forcing the
> data in with assignment statements.
I think this should work:
Dim MyXL As Excel.Application
Dim MyWB As Excel.Workbook
Dim MySheet As Excel.Worksheet
Const MyPath As String = "X:\"
Const WBName As String = "DataXL.xls"
Dim MyList() As Variant
Set MyXL = New Excel.Application
Set MyWB = MyXL.Workbooks.Open(MyPath & WBName)
Set MySheet = MyWB.Sheets("Sheet1")
MyList = MySheet.Range("A1", "C10").Value

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
John Viall - 26 Nov 2004 06:05 GMT
Thanks, the top part of your reply worked, however the second part regarding
opening an Excel spreadsheet gave me an error, on the first line.
Just for troubleshooting, and to examine the code, I put it into a
Subroutine called OpenExcel.
It highlights the following:
MyXL As Excel.Application
And gives the error, User-defined type not defined.
While at it, is there a way to determine the path of the original Word
Template, and use that to find the Worksheet?
Thanks again,
John
> John Viall was telling us:
> John Viall nous racontait que :
[quoted text clipped - 32 lines]
>
> MyList = MySheet.Range("A1", "C10").Value
Jean-Guy Marcil - 26 Nov 2004 06:47 GMT
John Viall was telling us:
John Viall nous racontait que :
> Thanks, the top part of your reply worked, however the second part
> regarding opening an Excel spreadsheet gave me an error, on the first
[quoted text clipped - 7 lines]
>
> And gives the error, User-defined type not defined.
Have you set a reference to the Excel Library?
In the VBA editor, Tools > References... > Check "Microsoft Excel..."
> While at it, is there a way to determine the path of the original Word
> Template, and use that to find the Worksheet?
You mean:
Dim MyPath as String
MyPath = ActiveDocument.AttachedTemplate.Path
?

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
John Viall - 28 Nov 2004 20:07 GMT
Thanks, it works great.
Is there a good reference book that shows the objects, properties and
methods for the Office suite?
Thanks again for your help.
> John Viall was telling us:
> John Viall nous racontait que :
[quoted text clipped - 23 lines]
>
> ?