I am not a designer/programmer. I am a Notes/Domino admin. But every niow and then I am asked to see if I can create/edit some code for a desired outcome.In this case, we need to add a button to a mail file so a user can open a doc, press this button and it will print the email and the contents of the attachment.
I found the following code online, which works great, but it does not address PDF files which is primarily what I need. Here is the whole code first:
Sub Click(Source As Button)
’This routine is set up to scan a document for attachments and then
’print them out automatically based on their file extension and ‘ ‘associated application.
Dim ws As New NotesUIWorkSpace
Dim session As New NotesSession
Dim dbThis As NotesDatabase
Dim uidocThis As NotesUIDocument
Dim docThis As NotesDocument
Dim embAttachment As NotesEmbeddedObject
Dim strFileUniqueID As String
Dim strAttachmentType As String
Dim strAttachmentName As String
Dim lngPrintDelay As Long
Set dbThis = session.CurrentDatabase
Set uidocThis = ws.CurrentDocument
Set docThis =uidocThis.Document
’This prints the actual Notes document prior to printing the ‘attachments.
Call uidocThis.Print(1)
strFileUniqueID = Format(Now, "yyyymmddhhmmss")
'By traversing all the item elements in the document, all attachments ‘should be snagged.
Forall i In docThis.Items
If i.type = Attachment Then
Set embAttachment = docThis.GetAttachment(i.values(0))
strAttachmentType = Right$(embAttachment.Name, 3)
strAttachmentName = "c:\temp\BRDocPrintAttachment" &
strFileUniqueID
Call embAttachment.ExtractFile(strAttachmentName)
Select Case Lcase(strAttachmentType)
'This routine prints txt files with the Notepad application running ‘under the /p print switch. It assumes that Notepad.exe is running in ‘c:\Windows.
Case "txt"
Dim strNotepadLocation As String
Dim intTaskID As Integer
strNotepadLocation = "c:\Windows\Notepad.exe"
intTaskID = Shell(strNotepadLocation & " /p" &
strAttachmentName)
Kill strAttachmentName
'This routine prints Excel files. It assumes that Excel is installed ‘on the machine doing the printing.
Case "xls"
Dim ExcelApp As Variant
Dim ExcelDoc As Variant
Set ExcelApp = CreateObject("Excel.Application")
Set ExcelDoc =
ExcelApp.Workbooks.Open(strAttachmentName)
Call ExcelDoc.PrintOut
Call ExcelDoc.Close(0)
Call ExcelApp.Quit
Set ExcelApp = Nothing
Kill strAttachmentName
'This routine prints Word files. It assumes that Word is
’installed on the machine doing the printing.
Case "doc"
Dim WordApp As Variant
Dim WordDoc As Variant
Set WordApp = CreateObject("Word.Application")
Set WordDoc =
WordApp.Documents.Open(strAttachmentName)
Call WordDoc.PrintOut
Call WordDoc.Close(0)
Call WordApp.Quit
Set WordApp = Nothing
Kill strAttachmentName
'This routine prints Visio files. It assumes that Visio
’is installed on the machine doing the printing.
Case "vsd"
Dim VisioApp As Variant
Dim VisioDoc As Variant
Set VisioApp = CreateObject("Visio.Application")
VisioApp.Visible = False
Set VisioDoc =
VisioApp.Documents.Open(strAttachmentName)
Call VisioDoc.Print
Call VisioApp.Quit
Set VisioApp = Nothing
Kill strAttachmentName
'This routine prints Microsoft Project files. It assumes
’that Microsoft Project is installed on the machine doing the printing.
Case "mpp"
Dim ProjectApp As Variant
Set ProjectApp =
CreateObject(“MSProject.Application”)
Call ProjectApp.FileOpen(strAttachmentName)
Call ProjectApp.FilePrint(1)
Call ProjectApp.FileClose(0)
Call ProjectApp.Quit
Set ProjectApp = Nothing
Kill strAttachmentName
'And if the attachment doesn’t have a recognized extension, we tell the ‘user to print the attachment manually.
Case Else
Msgbox "This routine doesn't recognize " +
strAttachmentType + " file types. Please print the attachment manually."
End Select
End If
End Forall
End Sub
Am I trying to add something like this for the PDF files:
'This routine prints PDF files. It assumes ’that Adobe Reader is installed on the machine doing the printing.
Case "pdf"
Dim AdobeReader8App As Variant
Set AdobeReader8App = CreateObject("Adobe Reader 8.Application")
Call AdobeReader8App.FileOpen(strAttachmentName)
Call AdobeReader8App.FilePrint(1)
Call AdobeReader8App.FileClose(0)
Call AdobeReader8App.Quit
Set AdobeReader8App = Nothing
Kill strAttachmentName
When I run this, I get “cannot create automation object”.
Any help would be greatly appreciated! Thanks in advance.