I was searching for a sample code to export the report into PDF and send it through the Outlook. I have found one at https://bobj-board.org/t/15915
However, it says ’ you must install MAPI in your BCA server for it to work’. What is MAPI? I’m trying to send it through the Microsoft Outlook. Is it possible? Could some tell me what MAPI is???
I just downloaded the zip file from the location and tried to run the vba. I got and error that says ‘Can’t find a project/library’ at As MAPI.Session line (the first line).
MAPI is Messaging Application Programming Interface. You should have a MAPI complient client, eg Outlook, Lotus Notes, Eudora etc… installed in the BCA server in order for you to be able to send e-mail using BCA.
This is the code (Please see the code in the bottom of this reply…) from the report that I have found from this website… If I could attach the report here, it may be more usefule, but don’t know how to attach… Anyways, when I try to run the macro, I get an error message “Can’t find project or library” at the first line, which is “Dim objSession As MAPI.Session ’ Local”.
I have Microsoft Outlook installed on my computer.
Why am I getting this error message?
Thank you four help…
thumper
Sub SendMailPDF()
Dim objSession As MAPI.Session ' Local
Dim objMessage As Message ' local
Dim objRecip As Recipient
On Error GoTo error_olemsg
Dim doc As busobj.IDocument
Dim rep As busobj.Report
Dim DPName As String
Dim test As Boolean
If ActiveDocument Is Nothing Then
MsgBox "NO Active Document to refresh"
Else
Set doc = ActiveDocument
If Not doc.IsAddIn Then
ActiveReport.ExportAsPDF ("C:\" & ActiveReport.Name & "_" & Format(Now, "mm_dd_yy") & ".pdf")
Else
End If
End If
Set objSession = CreateObject("MAPI.Session")
'Use a profile which exists on your Exchange Server as mailid.We created bo_admin for ours
objSession.Logon profileName:="bo_admin", newSession:=False, showDialog:=False
If objSession Is Nothing Then
Err.Raise 10, "MA MACRO", "must first log on; use Session->Logon"
Exit Sub
End If
Set objMessage = objSession.Outbox.Messages.Add
If objMessage Is Nothing Then
Err.Raise 11, "MA MACRO", "could not create a new message in the Outbox"
Exit Sub
End If
With objMessage ' message object
'Substitute with your subject
.Subject = "Daily Report"
'Substitue with your message
.Text = "The Daily report is attached herewith "
.Text = .Text & ActiveReport.Name & "_" & Format(Now, "mm_dd_yy") & ".pdf"
Set objAttach = .Attachments.Add ' add the attachment
If objAttach Is Nothing Then
Err.Raise 12, "MA MACRO", "Unable to create new Attachmentobject"
Exit Sub
End If
With objAttach
.Name = ActiveReport.Name & "_" & Format(Now, "mm_dd_yy") & ".pdf"
.Source = "C:\" & ActiveReport.Name & "_" & Format(Now, "mm_dd_yy") & ".pdf"
End With
.Update ' update message to save attachment in MAPI system
Set objRecip = .Recipients.Add
With objRecip
objRecip.Name = ("grpname") 'Substitute with individual mailid or groupname
objRecip.Type = CdoTo
objRecip.Resolve
End With
Set objRecip = .Recipients.Add
With objRecip
objRecip.Name = ("name") 'Substitute with individual mailid or groupname
objRecip.Type = CdoCc
objRecip.Resolve
End With
.Update
' update message to save attachment in MAPI system
.Send showDialog:=False
End With
Kill "C:\" & ActiveReport.Name & "_" & Format(Now, "mm_dd_yy") & ".pdf"
objSession.Logoff
Exit Sub
error_olemsg:
'MsgBox "Error " & Str(Err) & ": " & Error$(Err)
Err.Raise 13, "MA MACRO", "Error " & Str(Err) & ": " & Error$(Err)
Resume Next
End Sub
Just check if the MAPI dll’s are correctly referenced in the VBA code. Open the VBA code, go to Tools -> References and see if MAPI is referenced. If not check the box to select it and then try.
I checked add-in. I have followings checked but still get the same error message
Visual Basic For Applications
BusinessObjects 5.1 Object Library
OLE Automation
Microsoft Forms 2.0 Object Library
MISSING: Microsoft CDO 1.21 Library
Messenger Type Library
Microsoft Outlook 9.0 Object Library
Any clue? Is there a way to send a file to an Outlook without doing this MAPI ?
You are missing a dll, the CDO one. I am not sure which one that is, but is has to do with VBA. I would check, but my pc is loaded down with a job right now.
Ok, I found C:\WINNT\system32\MAPI.DLL. However, when I try to add it by “Tools”-“References…”-“Browse”-“C:\WINNT\system32\MAPI.DLL” and “OK”, I get an error message, which is “Can’t add a reference to the specified file.”
Sorry for this bother…
I really appreciate your help…
Did you check the registry to ensure that your MAPI.dll and CDO.dll are properly registered (I would also double check the other DLLs)? If not, you could run “regsvr32” at the command line, followed by a blank, followed by the name of the DLL you would like to register.
I think that is because you already have a reference to it with the outlook reference. The problem is the CDO reference dll missing. Here is where it is on my machine, I am in 2000, yours might be in a slightly different place.
You would also need to add a reference to both “Microsoft Exchange 5.5 ACL Type Library 1.0” and “Microsoft CDO 1.2 library” or “Microsoft CDO 1.21 library”
I dont think you need the exchange reference unless you are working on the actual exchange server, I have never used that dll. The CDO dll is missing, or in a different location from the person that wrote the module. In one of the posts there is this:
Get that straightened out and the code should work. Do a search for cdo.dll, then just go to the references and browse for the dll under that refreence.