Discussion:
MVP.Org pseudoautomacros: How to...
(too old to reply)
JeffP@Laptop
2006-10-25 18:25:57 UTC
Permalink
I'm having a problem implementing this programming...

ref: http://word.mvps.org/faqs/macrosvba/pseudoautomacros.htm

Word2000

I have added to my existing "ADOTemplate" module the code

Option Explicit

Dim oAppClass As New ThisApplication
Public oldNoOfOpenDocs As Long
Public FirstNewDoc As Boolean

Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
oldNoOfOpenDocs = 0
FirstNewDoc = True
End Sub

I added a class module "ThisApplication" with....

Option Explicit

Public WithEvents oApp As Word.Application
---------------------------------------------------------------------
Private Sub oApp_DocumentChange()

On Error GoTo ExitCode

Dim newNoOfOpenDocs As Long
.......ending....
Call DocChangedFocus
End If

Exit Sub

ExitCode:

End Sub

Q1: Should the oApp_DocumentChange() be in my "ADOTemplate" module or the
ThisApp class module ?

Q2: Should the oApp_DocumentOpen() be in the "ThisDocument" class module?

Q2b: How does the Doc in "oApp_DocumentOpen(ByVal Doc as Document)" get
passed in, looking at the code it appears that it's implied?

TIA

JeffP...
Jezebel
2006-10-25 20:24:33 UTC
Permalink
Post by ***@Laptop
I'm having a problem implementing this programming...
ref: http://word.mvps.org/faqs/macrosvba/pseudoautomacros.htm
Word2000
I have added to my existing "ADOTemplate" module the code
Option Explicit
Dim oAppClass As New ThisApplication
Public oldNoOfOpenDocs As Long
Public FirstNewDoc As Boolean
Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
oldNoOfOpenDocs = 0
FirstNewDoc = True
End Sub
I added a class module "ThisApplication" with....
Option Explicit
Public WithEvents oApp As Word.Application
---------------------------------------------------------------------
Private Sub oApp_DocumentChange()
On Error GoTo ExitCode
Dim newNoOfOpenDocs As Long
.......ending....
Call DocChangedFocus
End If
Exit Sub
End Sub
Q1: Should the oApp_DocumentChange() be in my "ADOTemplate" module or the
ThisApp class module ?
Q2: Should the oApp_DocumentOpen() be in the "ThisDocument" class module?
Q2b: How does the Doc in "oApp_DocumentOpen(ByVal Doc as Document)" get
passed in, looking at the code it appears that it's implied?
TIA
JeffP...
"" <jpgmt_at_sbcglobal_dot_net>
2006-10-25 20:37:29 UTC
Permalink
I've got the process working... BUT

I'm not finding a way to envoke the methods when printing (right-click
|Print)

JeffP.....
Post by ***@Laptop
I'm having a problem implementing this programming...
ref: http://word.mvps.org/faqs/macrosvba/pseudoautomacros.htm
Word2000
I have added to my existing "ADOTemplate" module the code
Option Explicit
Dim oAppClass As New ThisApplication
Public oldNoOfOpenDocs As Long
Public FirstNewDoc As Boolean
Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
oldNoOfOpenDocs = 0
FirstNewDoc = True
End Sub
I added a class module "ThisApplication" with....
Option Explicit
Public WithEvents oApp As Word.Application
---------------------------------------------------------------------
Private Sub oApp_DocumentChange()
On Error GoTo ExitCode
Dim newNoOfOpenDocs As Long
.......ending....
Call DocChangedFocus
End If
Exit Sub
End Sub
Q1: Should the oApp_DocumentChange() be in my "ADOTemplate" module or the
ThisApp class module ?
Q2: Should the oApp_DocumentOpen() be in the "ThisDocument" class module?
Q2b: How does the Doc in "oApp_DocumentOpen(ByVal Doc as Document)" get
passed in, looking at the code it appears that it's implied?
TIA
JeffP...
Jezebel
2006-10-25 21:54:12 UTC
Permalink
Which methods? The code you've created traps *events*.
Post by "" <jpgmt_at_sbcglobal_dot_net>
I've got the process working... BUT
I'm not finding a way to envoke the methods when printing (right-click
|Print)
JeffP.....
Post by ***@Laptop
I'm having a problem implementing this programming...
ref: http://word.mvps.org/faqs/macrosvba/pseudoautomacros.htm
Word2000
I have added to my existing "ADOTemplate" module the code
Option Explicit
Dim oAppClass As New ThisApplication
Public oldNoOfOpenDocs As Long
Public FirstNewDoc As Boolean
Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
oldNoOfOpenDocs = 0
FirstNewDoc = True
End Sub
I added a class module "ThisApplication" with....
Option Explicit
Public WithEvents oApp As Word.Application
---------------------------------------------------------------------
Private Sub oApp_DocumentChange()
On Error GoTo ExitCode
Dim newNoOfOpenDocs As Long
.......ending....
Call DocChangedFocus
End If
Exit Sub
End Sub
Q1: Should the oApp_DocumentChange() be in my "ADOTemplate" module or
the ThisApp class module ?
Q2: Should the oApp_DocumentOpen() be in the "ThisDocument" class module?
Q2b: How does the Doc in "oApp_DocumentOpen(ByVal Doc as Document)" get
passed in, looking at the code it appears that it's implied?
TIA
JeffP...
"" <jpgmt_at_sbcglobal_dot_net>
2006-10-25 23:11:42 UTC
Permalink
Ok, it works for any user that will open and prehaps edit the doc which is
about 1 out of 10 times.

The other times the doc is printed similar to the right-click.

I was hoping that there was an application event for the printing.

I even tried adding some of this same code for events in the template and
removed it from the addin, but although it basically works, the right-click
print still does not with the added pain of being prompted for the macro
security.

My only choice seems to be to set the security low :-(

... and re-place my AutoExec()

The whole problem arrose because I didn't check my security settings which
were low, and when I went to install my template and the addin which has
it's own install module, and addin checking w/in the template its self.

It was working perfectly w/low security, using AutoExec()

What's a novice VBA programmer to do... ?

JeffP.....
Post by Jezebel
Which methods? The code you've created traps *events*.
Post by "" <jpgmt_at_sbcglobal_dot_net>
I've got the process working... BUT
I'm not finding a way to envoke the methods when printing (right-click
|Print)
JeffP.....
Post by ***@Laptop
I'm having a problem implementing this programming...
ref: http://word.mvps.org/faqs/macrosvba/pseudoautomacros.htm
Word2000
I have added to my existing "ADOTemplate" module the code
Option Explicit
Dim oAppClass As New ThisApplication
Public oldNoOfOpenDocs As Long
Public FirstNewDoc As Boolean
Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
oldNoOfOpenDocs = 0
FirstNewDoc = True
End Sub
I added a class module "ThisApplication" with....
Option Explicit
Public WithEvents oApp As Word.Application
---------------------------------------------------------------------
Private Sub oApp_DocumentChange()
On Error GoTo ExitCode
Dim newNoOfOpenDocs As Long
.......ending....
Call DocChangedFocus
End If
Exit Sub
End Sub
Q1: Should the oApp_DocumentChange() be in my "ADOTemplate" module or
the ThisApp class module ?
Q2: Should the oApp_DocumentOpen() be in the "ThisDocument" class module?
Q2b: How does the Doc in "oApp_DocumentOpen(ByVal Doc as Document)" get
passed in, looking at the code it appears that it's implied?
TIA
JeffP...
Jonathan West
2006-10-25 23:10:34 UTC
Permalink
Post by "" <jpgmt_at_sbcglobal_dot_net>
I've got the process working... BUT
I'm not finding a way to envoke the methods when printing (right-click
|Print)
Use the DocumentBeforePrint event. look it up in the VBA help.
--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Jezebel
2006-10-25 20:35:36 UTC
Permalink
Post by ***@Laptop
I'm having a problem implementing this programming...
ref: http://word.mvps.org/faqs/macrosvba/pseudoautomacros.htm
Word2000
I have added to my existing "ADOTemplate" module the code
Option Explicit
Dim oAppClass As New ThisApplication
Public oldNoOfOpenDocs As Long
Public FirstNewDoc As Boolean
Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
oldNoOfOpenDocs = 0
FirstNewDoc = True
End Sub
I added a class module "ThisApplication" with....
Option Explicit
Public WithEvents oApp As Word.Application
---------------------------------------------------------------------
Private Sub oApp_DocumentChange()
On Error GoTo ExitCode
Dim newNoOfOpenDocs As Long
.......ending....
Call DocChangedFocus
End If
Exit Sub
End Sub
Q1: Should the oApp_DocumentChange() be in my "ADOTemplate" module or the
ThisApp class module ?
Event functions have to be in the module in which the withevents variable
(oApp in this case) is declared. And you can use withevents only in a class
module.
Post by ***@Laptop
Q2: Should the oApp_DocumentOpen() be in the "ThisDocument" class module?
As for question 1 -- it has to be where you declared oApp. And it has to be
declared as

oApp_DocumentOpen(ByVal Doc as Document).

Once you've added the withevents declaration, you can select the variable
from the drop down at the top-left of the code window where you normally see
'(general)' or 'Class', then select the function from the drop-down on the
right. The arguments are supplied automatically.
Loading...