Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

Automate a form textbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Viall - 23 Nov 2004 04:55 GMT
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
Jean-Guy Marcil - 23 Nov 2004 07:06 GMT
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]
>
> ?

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.