Accessing Word 97 functions & sub's 
Author Message
 Accessing Word 97 functions & sub's

Is there any way to initialise a word template that has some functions in
it. Call one of those functions or subs sending it a value. Any help would
be great.

--
Kenneth Lea
Software Developer



Sun, 22 Apr 2001 03:00:00 GMT  
 Accessing Word 97 functions & sub's

Hi Kenneth

If you mean start Word from VB, load the file and call a macro , then yes.
There is one big drawback, you cannot call the macro with parameters.
However, what you can do is to define document variables in the template,
something like this in the Visual Basic Editor of Word 97:

Documents("your_document").Variables.Add "name", value
Note: if you try to use the name of an existing variable an error occurs

These variables are persistant, that is, they are saved when you save the
document

Documents("your_document").Variables("your_name").Value = yourvalue

Heres a simple example snippet, needs MicroSoft Word 8.0 in the VB project
references:

Option Explicit

Private appWord As Word.Application
Private strmyfile As String

Private Sub InitWord()
On Error GoTo error_handler
    strmyfile = "c:\strmyfile.doc"

note: here we try to connect to an existing instance of word, if it does not
exist, an error is raised and control is transferred to the error_handler
line.
    Set appWord = GetObject(, "Word.Application")

Word is already open so add your file to the documents collection
    appWord.Documents.Add strmyfile

initialise your document variables
    Documents("your_document").Variables("your_name").Value = yourvalue
    ....
    Documents("your_document").Variables("your_name").Value = yourvalue

Now call the macro in the Word document
    Application.Run ("pubcode.Generate")

    now your macro can access these variables

    Exit Sub

error_handler:

    execute Word
    Set appWord = CreateObject("Word.Application")

    appWord.Documents.Add strmyfile

    appWord.Visible = True

same for above.....

End Sub

Hope this helps
Nigel Rowe



Mon, 23 Apr 2001 03:00:00 GMT  
 Accessing Word 97 functions & sub's
That's a great help. I will give it a try.

Cheers

Ken

Quote:

>Hi Kenneth

>If you mean start Word from VB, load the file and call a macro , then yes.
>There is one big drawback, you cannot call the macro with parameters.
>However, what you can do is to define document variables in the template,
>something like this in the Visual Basic Editor of Word 97:

>Documents("your_document").Variables.Add "name", value
>Note: if you try to use the name of an existing variable an error occurs

>These variables are persistant, that is, they are saved when you save the
>document

>Documents("your_document").Variables("your_name").Value = yourvalue

>Heres a simple example snippet, needs MicroSoft Word 8.0 in the VB project
>references:

>Option Explicit

>Private appWord As Word.Application
>Private strmyfile As String

>Private Sub InitWord()
>On Error GoTo error_handler
>    strmyfile = "c:\strmyfile.doc"

>note: here we try to connect to an existing instance of word, if it does
not
>exist, an error is raised and control is transferred to the error_handler
>line.
>    Set appWord = GetObject(, "Word.Application")

>Word is already open so add your file to the documents collection
>    appWord.Documents.Add strmyfile

>initialise your document variables
>    Documents("your_document").Variables("your_name").Value = yourvalue
>    ....
>    Documents("your_document").Variables("your_name").Value = yourvalue

>Now call the macro in the Word document
>    Application.Run ("pubcode.Generate")

>    now your macro can access these variables

>    Exit Sub

>error_handler:

>    execute Word
>    Set appWord = CreateObject("Word.Application")

>    appWord.Documents.Add strmyfile

>    appWord.Visible = True

>same for above.....

>End Sub

>Hope this helps
>Nigel Rowe



Tue, 24 Apr 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing Userforms to subs (Word 2000 and 2002, I did not try Word 97)

2. VB's help compiler & Word 97

3. Accessing the Word 97 spell checking functions

4. Recordset index problem Word 97 & Access 2000

5. Problem w/Access 97 & Word Object

6. Access '97 VBA functions missing.

7. Access 97 doesn't understand VBA functions

8. Access 97' to Word 8.0

9. Word 8.0 Access 97' problem

10. Module function won't compile in Access 97 Runtime

11. FORMAT function doesn't work in Access 97

12. Performing Access '97 Functions in VB5

 

 
Powered by phpBB® Forum Software