Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you use Automatic BeforePrint event in Word

Status
Not open for further replies.

ACH381

Technical User
Apr 3, 2002
49
US
Is there a way to use a BeforePrint Event in Word 2000 without creating a new Class Module? I'm needing to run a script automatically when the user invokes a print command. Word did not inherently have a BeforePrint event available without creating a new Class Module to create the DocumentsBeforePrint event.

"Public WithEvents MyWord As Word.Application

Public Sub MyWord_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
On Error Resume Next
If Options.BlueScreen = True Then
Day
End If
End Sub"


To make a long story short, I must have all word templates create "template independent documents", so I had to write a script that copies all the scripts from the template to every document that gets created off the template. When I added the syntax to copy the Class Module, McAfee Virus Scan sees it as a virus and deletes all the scripts from the template. Below is the script that causes McAfee to balk:


'This section copies the Module1 in the .dot to Module1 in the .doc; the Word Application Class module in the dot. to the doc; and the InstDlgBox module in the dot to the doc.

TemplateName = Application.ActiveDocument.AttachedTemplate.FullName
FileName = Application.ActiveDocument.FullName

Application.OrganizerCopy _
Source:=TemplateName, _
Destination:=FileName, _
Name:="Module1", _
Object:=wdOrganizerObjectProjectItems

Application.OrganizerCopy _
Source:=TemplateName, _
Destination:=FileName, _
Name:="WordApplication", _
Object:=wdOrganizerObjectProjectItems

'Comment out next next5 lines if Instruction Dialog Box not used
Application.OrganizerCopy _
Source:=TemplateName, _
Destination:=FileName, _
Name:="InstDlgBox", _
Object:=wdOrganizerObjectProjectItems

'This section copies all the Scripts from ThisDocument in the .dot to the new .doc.
Application.ActiveDocument.AttachedTemplate.VBProject.VBComponents.Item(1).Export "C:\ScriptFiles.sys"
 
This is a problem of AV software, so maybe other transfer method will work.
I wrote a piece of code to copy the class module "EventClassModule" to new workbook, without writing it to file:

[tt]Private Sub App_NewDocument(ByVal Doc As Document)
Dim cModule As VBComponent, cSourceModule As VBComponent
Dim iLines as Long
Set cSourceModule = ThisDocument.VBProject.VBComponents.Item("EventClassModule")
Set cModule = Doc.VBProject.VBComponents.Add(vbext_ct_ClassModule)
iLines = cSourceModule.CodeModule.CountOfLines
With cModule
.Name = cSourceModule.Name
.CodeModule.InsertLines 1, cSourceModule.CodeModule.Lines(1, iLines)
End With
End Sub[/tt]

(NB, I have not heard about tracing printing without using class.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top