Automate a form textbox

J

John Viall

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
 
J

Jean-Guy Marcil

John Viall was telling us:
John Viall nous racontait que :
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.

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


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

John Viall

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
 
J

Jean-Guy Marcil

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
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.

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

?
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

John Viall

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.
 

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