How to run Word macro from Access? 
Author Message
 How to run Word macro from Access?

Hello all,

I have a Word macro called "Test" stored in Word's default template,
Normal.dot. I would like to open Word and run this "Test" macro. Has anyone
done this before in an Access97 module?

Thanks in advance,

Bob



Sun, 18 Aug 2002 03:00:00 GMT  
 How to run Word macro from Access?
Try this.

Sub RunWordMacro()

    Dim strPathDoc As String
    Dim oWord As Object

    Set oWord = CreateObject("Word.Application")
    strPathDoc = "YourPathAndDocumentNameHere"

    With oWord
        .Documents.Open FileName:=strPathDoc
        .Run MacroName:="YourMacroNameHere"
        .ActiveDocument.Close SaveChanges:=False
        .Quit
    End With

End Sub


Quote:
> Hello all,

> I have a Word macro called "Test" stored in Word's default template,
> Normal.dot. I would like to open Word and run this "Test" macro. Has
anyone
> done this before in an Access97 module?

> Thanks in advance,

> Bob



Sun, 18 Aug 2002 03:00:00 GMT  
 How to run Word macro from Access?
Hi Jack,

Thanks, that worked great! When Word ran, it ran minimized. Is there a way
to dictate the mode of the window, or would that make this code way too big?

Thanks,

Bob


Quote:
> Try this.

> Sub RunWordMacro()

>     Dim strPathDoc As String
>     Dim oWord As Object

>     Set oWord = CreateObject("Word.Application")
>     strPathDoc = "YourPathAndDocumentNameHere"

>     With oWord
>         .Documents.Open FileName:=strPathDoc
>         .Run MacroName:="YourMacroNameHere"
>         .ActiveDocument.Close SaveChanges:=False
>         .Quit
>     End With

> End Sub



> > Hello all,

> > I have a Word macro called "Test" stored in Word's default template,
> > Normal.dot. I would like to open Word and run this "Test" macro. Has
> anyone
> > done this before in an Access97 module?

> > Thanks in advance,

> > Bob



Sun, 18 Aug 2002 03:00:00 GMT  
 How to run Word macro from Access?
Two more things I noticed:

The macro calls for me to open a file, and when the macro stops, I still
have a temp Word file (i.e., "~test.doc") open. Can I do this and just open
Word? Also, do I need some kind of command to release the oWord variable,
something like "oWord.Close"?

Bob


Quote:
> Try this.

> Sub RunWordMacro()

>     Dim strPathDoc As String
>     Dim oWord As Object

>     Set oWord = CreateObject("Word.Application")
>     strPathDoc = "YourPathAndDocumentNameHere"

>     With oWord
>         .Documents.Open FileName:=strPathDoc
>         .Run MacroName:="YourMacroNameHere"
>         .ActiveDocument.Close SaveChanges:=False
>         .Quit
>     End With

> End Sub



> > Hello all,

> > I have a Word macro called "Test" stored in Word's default template,
> > Normal.dot. I would like to open Word and run this "Test" macro. Has
> anyone
> > done this before in an Access97 module?

> > Thanks in advance,

> > Bob



Sun, 18 Aug 2002 03:00:00 GMT  
 How to run Word macro from Access?
Bob,

Try "Set oWord = Nothing" to release.  I should have included that earlier.

Are you closing the file that you open through the macro?  If not you'll
need to alter the macro or close it through the code.  Also, in my
experience (which is limited with Word) the code runs much slower when the
Word application is open and visible.  Albeit I was looping through about 60
fields and 120 documents.

Jack

Quote:

>Two more things I noticed:

>The macro calls for me to open a file, and when the macro stops, I still
>have a temp Word file (i.e., "~test.doc") open. Can I do this and just open
>Word? Also, do I need some kind of command to release the oWord variable,
>something like "oWord.Close"?

>Bob



Sun, 18 Aug 2002 03:00:00 GMT  
 How to run Word macro from Access?
Here is the solution.

oWord.Application.Quit ' Explaines it self
You also can use
.documents("YourdocumentName").close

For more info use the exellent macro recorder it solves all your problems
just record what you are going to do and then you see what m$ does.
It gives at least away the objects.
just alt+F11 after stopping the recorder. ok

Bjarni Fridjonsson
Loke Data as


Quote:
> Hi Jack,

> Thanks, that worked great! When Word ran, it ran minimized. Is there a way
> to dictate the mode of the window, or would that make this code way too
big?

> Thanks,

> Bob



> > Try this.

> > Sub RunWordMacro()

> >     Dim strPathDoc As String
> >     Dim oWord As Object

> >     Set oWord = CreateObject("Word.Application")
> >     strPathDoc = "YourPathAndDocumentNameHere"

> >     With oWord
> >         .Documents.Open FileName:=strPathDoc
> >         .Run MacroName:="YourMacroNameHere"
> >         .ActiveDocument.Close SaveChanges:=False
> >         .Quit
> >     End With

> > End Sub



> > > Hello all,

> > > I have a Word macro called "Test" stored in Word's default template,
> > > Normal.dot. I would like to open Word and run this "Test" macro. Has
> > anyone
> > > done this before in an Access97 module?

> > > Thanks in advance,

> > > Bob



Sun, 25 Aug 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Running Word Macro in Access

2. Run word macro from Access module code

3. Run Word Macro from Access

4. Running Macros on Word OLE objects in Access

5. Word Macro runs then gets Macro Not Found

6. Word Macro runs then gets Macro Not Found

7. Running a word Macro & an excel macro

8. My Word 97 macros don't run in Word 2000

9. Word 2000 macro running under Word 97

10. Word 97 Macros > Word XP Macros

11. New instance of word every time macro runs?

12. Running a macro with arguments on Word 2000 startup

 

 
Powered by phpBB® Forum Software