PDA

View Full Version : How to make a great deal of document file totally used a VBA macro



hsw1976
11-01-2010, 09:37 PM
Hello all,


I wrote a Word VBA to do "Automatic creation watermark when print out" and the code almost completed.

but how to make greater than 5,000 document files to run this VBA code?

I have had thinking about to paste the code in nomoral.dot but it will makes me some trouble: all document files will running this VBA (coz not each file are necessary to have watermark)

any idea guys?

Tinbendr
11-02-2010, 03:23 AM
Welcome to VBA Express!

If you have posted this on another forum, please provide the link to that message.

Something like...
Sub FilePrint() 'Catches File/Print command
On Error GoTo Oops
If MsgBox("Do you wish to add watermark?", _
vbQuestion + vbYesNo, "Add Watermark") = vbYes Then
AddWatermark
Dialogs(wdDialogFilePrint).Show
End If
Oops:
End Sub
Sub FilePrintDefault() 'Catches Toolbar Print button
On Error GoTo Oops
If MsgBox("Do you wish to add watermark?", _
vbQuestion + vbYesNo, "Add Watermark") = vbYes Then
AddWatermark
ActiveDocument.PrintOut
End If
Oops:
End Sub

Sub AddWatermark()
'Your code here
End Sub

Not tested.

fumei
11-04-2010, 09:09 AM
Are all your files in the same folder? To do multiple processing of the same set of instructions look at the DIR function.

hsw1976
11-06-2010, 10:58 PM
Welcome to VBA Express!

If you have posted this on another forum, please provide the link to that message.

Something like...
Sub FilePrint() 'Catches File/Print command
On Error GoTo Oops
If MsgBox("Do you wish to add watermark?", _
vbQuestion + vbYesNo, "Add Watermark") = vbYes Then
AddWatermark
Dialogs(wdDialogFilePrint).Show
End If
Oops:
End Sub
Sub FilePrintDefault() 'Catches Toolbar Print button
On Error GoTo Oops
If MsgBox("Do you wish to add watermark?", _
vbQuestion + vbYesNo, "Add Watermark") = vbYes Then
AddWatermark
ActiveDocument.PrintOut
End If
Oops:
End Sub

Sub AddWatermark()
'Your code here
End Sub

Not tested.

this way is sounds great. so how can I make the other computers to run this MACRO without?

hsw1976
11-06-2010, 11:03 PM
Are all your files in the same folder? To do multiple processing of the same set of instructions look at the DIR function.

In actually, these files are in the same folder (thanks God).

fumei
11-09-2010, 09:42 AM
I doubt if any deity has anything to do with it.

Please clarify what you are asking.

You want to add code to print 5,000 documents, adding a watermark for each printing?

This is theoretically possible, although I have concerns about Word and memory usage with that many files.

However, again, to process instructions on many files, in the same folder:
Sub LotsOfFiles()
Dim file
Dim path As String
path = "c:\Blah\Whatever\" ' this is the folder path

file = Dir(path & "*.doc")
Do While file <> ""
Documents.Open Filename:=path & file
Call DoMyStuffEachFile ' call to procedure processing each file
file = Dir()
Loop
End Sub


Sub DoMyStuffEachFile()
' whatever it is you are doing to each file
ActiveDocument.Save '??? are you saving each file ??
ActiveDocument.PrintOut '??? are you printing each file
End Sub


Each .doic file in the folder will be actioned by the Sub DoMyStuffEachFile.

hsw1976
11-18-2010, 03:40 AM
I doubt if any deity has anything to do with it.

Please clarify what you are asking.

You want to add code to print 5,000 documents, adding a watermark for each printing?

This is theoretically possible, although I have concerns about Word and memory usage with that many files.

However, again, to process instructions on many files, in the same folder:
Sub LotsOfFiles()
Dim file
Dim path As String
path = "c:\Blah\Whatever\" ' this is the folder path

file = Dir(path & "*.doc")
Do While file <> ""
Documents.Open Filename:=path & file
Call DoMyStuffEachFile ' call to procedure processing each file
file = Dir()
Loop
End Sub


Sub DoMyStuffEachFile()
' whatever it is you are doing to each file
ActiveDocument.Save '??? are you saving each file ??
ActiveDocument.PrintOut '??? are you printing each file
End Sub


Each .doic file in the folder will be actioned by the Sub DoMyStuffEachFile.

It should be say:

1. Just adding a watermark "only when" printing or previewing.
2. 5000 documents in the same folder is condition known. but I cannot guarantee other documents (in difference folder) whether need to add watermark.