Tip

Script To Print Automatically All The .Xls Or .Doc Or .Ppt Attachments In Documents

This script will print all the .xls or .doc or .ppt attachments in selected
documents in a view. This is very useful in maildatabases. user doesn't need to
launch each attachment in each document. I am not very good at OLE. but while
helping a friend I came up with this script. If it needs any modification or
if any one have any better method please modify the script and post in this
forum.

Thanks.
Surendra Kumar Talluri
Sub Initialize
Dim session As New notessession
Dim db As notesdatabase
Dim doc As notesdocument
Dim dc As notesdocumentcollection
Dim rtitem As notesrichtextitem
Dim loopindex As Long
Dim poc As Integer
Dim resul As String
Dim xlapp As Variant
Set db = session.currentdatabase
Set dc = db.Unprocesseddocuments
For loopindex = 1 To dc.count
Set doc = dc.getnthdocument(loopindex)
If (doc.hasitem("$File")) Then
Set rtitem = doc.getfirstitem("Body")
Forall eo In rtitem.embeddedobjects
If (eo.Type= EMBED_ATTACHMENT) Then
fname = "C:\TEMP\" & eo.Source
poc = Instr(1, fname, ".")
resul = Mid$(fname, poc, 4)

If Lcase$(resul) = ".xls" Then
Call eo.extractfile(fname)
Set xlapp = createobject("Excel.application")
xlapp.visible = True
xlapp.workbooks.open (fname)
Print("Printing Attachment : "&eo.Source)
Call xlapp.Activesheet.printout
' the follwing loop is to avoid any warning
message the 'application prompts some times like
" the current document is 'still in the
process of printing. do you want to continue printing
or 'cancel"
For i =1 To 100000
Next
Call xlapp.workbooks.close
Call xlapp.quit
End If
If Lcase$(resul) = ".doc" Then
Call eo.extractfile(fname)
Set xlapp = createobject("Word.application")
xlapp.visible = True
xlapp.documents.open(fname)
Print("Printing Attachment : "&eo.Source)
xlapp.PrintOut(FileName=fname)
For i =1 To 100000
Next
xlapp.Quit savechanges=False
End If
If Lcase$(resul) = ".ppt" Then
Call eo.extractfile(fname)
Set xlapp = createobject("PowerPoint.application")
xlapp.visible = True
xlapp.presentations.open(fname)
Print("Printing Attachment : "&eo.Source)
xlapp.ActivePresentation.PrintOut
For i =1 To 100000
Next
xlapp.activepresentation.close
xlapp.Quit
End If
End If
End Forall
Print(" ")
End If
Next
End Sub

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.