Hi,
I am giving you the code to send email through bca or whenever you run your report.
Follow the below steps:
Open the report;
click on >> Macro >> Macros.
Create a new Macro and attach the below given codes.
Also in the code give the smtp server your cmpy is using.( in last but 4 line). Also change the server port according to your cmpy.
Creat a folder ClientReports under C drive. and run the report.
Hope this work out for you…
Let me know of any issue.
Dim strComputer As String
Dim strClientName As String
Dim strClientID As String
Dim objFSO
Dim objTextFile
Dim strResponses As String
Dim strEmailAddrs As String
Dim objEmail
Dim strEmailSubject As String
Dim strAttachPath As String
Dim strAttachFileName As String
Dim strAttachFile As String
Dim strEmailBodyText As String
Dim strReportType As String
Dim Doc As Document
Dim Rpt As Report
Dim I As Integer
Dim j As Integer
Dim xlsApp As Object
Dim strICount As String
Private Sub Document_AfterRefresh()
Init
End Sub
'***************************************************************************************
'Master sub for getting the email started
'***************************************************************************************
Sub Init()
Const ForReading = 1
strAttachPath = “c:\ClientReports”
strReportType = “excel”
'***************************************************************************************
'Only edit this section of the script.
'Put the email addresses between the quotes in this line strEmailAddrs
’ i.e. Ram@ramayana.com;sita@ramayana.com
’ REPORT FORMAT IS EXCEL
'Put the subject of the email between the quotes in this line strEmailSubject
'Put the text of the email between the quotes in this line strEmailBodyText
'strICount is the amount of data that the report will contain
strEmailAddrs = “Ram@ramayana.com;sita@ramayana.com”
strEmailSubject = “Hello Baby”
strEmailBodyText = “Attached is the Report.”
strICount = 500
'***************************************************************************************
GetReportType
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set xlsApp = CreateObject(“Excel.Application”)
’ xlsApp.Visible = False
’ xlsApp.Interactive = False
xlsApp.Workbooks.Open Filename:=strAttachFile
'DelRowCol
xlsApp.Range(“A1”).Select
xlsApp.ActiveWorkbook.Save
xlsApp.ActiveWindow.Close
xlsApp.Workbooks.Close
xlsApp.Quit
Set xlsApp = Nothing
SendClientEmail
End Sub
'***************************************************************************************
'Sub for getting the report type and exporting as that type
'***************************************************************************************
Sub GetReportType()
Select Case UCase(strReportType)
Case “EXCEL”
ExportDocAsEXCEL
End Select
End Sub
'***************************************************************************************
'Sub for Exporting Report as Excel (.XLS)
'***************************************************************************************
Sub ExportDocAsEXCEL()
Set Doc = ActiveDocument
For I = 1 To Doc.Reports.Count
Set Rpt = Doc.Reports.Item(I)
Rpt.ExportAsEXCEL (strAttachPath & Rpt.Name & “1.xls”)
Next I
strAttachFile = (strAttachPath & Rpt.Name & “1.xls”)
End Sub
'***************************************************************************************
'Sub for sending email with report as attachment
'***************************************************************************************
Sub SendClientEmail()
Set objEmail = CreateObject(“CDO.Message”)
objEmail.From = “BusinessObjects”
objEmail.To = strEmailAddrs
objEmail.Subject = strEmailSubject
objEmail.TextBody = strEmailBodyText
objEmail.AddAttachment (strAttachFile)
objEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2
objEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “yourserver.com”
objEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25
objEmail.Configuration.Fields.Update
objEmail.Send
Set objEmail = Nothing
End Sub
Anand Sahu (BOB member since 2005-08-03)