Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
hello to every one,
I really tried to do it, but I cant get a solution:
I have list of email so select for sendind them a report in PDF. my code is the following one, and yes, I know there are errors in it because it only create 1 PDf and it doesnt send it .....
Sub sendPDF
testo="ESEGUI"
msg=msgbox(testo,1)
if msg=1 then
Dim destPath, NomeFile
Dim objEmail
Const cdoSendUsingPort = 2
Const cdoAnonymous = 0
Const cdoBasic = 1
Const cdoNTLM = 2
Const SMTPServer = "XXXXXXXXXX" 'IP server
Const SMTPPort = 25
Const SMTPTimeout = 60
destPath = ActiveDocument.Variables("print_path").GetContent.String
set table = ActiveDocument.GetSheetObject( "YYYYYY")
set f = ActiveDocument.Fields("FIELD")
set fv = f.GetNoValues
h = table.GetRowCount
lista=""
set CellMatrix = table.GetCells2(0,1,1,h-1)
for RowIter=0 to h-2
fv.Add
fv(RowIter).Text = CellMatrix(RowIter)(0).Text
fv(RowIter).IsNumeric = false
next
set agente=fv
For i = 0 to h-2
ActiveDocument.Fields("FIELD").Select(agente.Item(i).Text)
NomeFile_TMP = TRIM(agente.Item(i).Text)
NomeFile_TMP = Replace(NomeFile_TMP, "/", "_")
NomeFile_TMP = Replace(NomeFile_TMP, "\", "_")
NomeFile_TMP = Replace(NomeFile_TMP, ":", "_")
NomeFile_TMP = Replace(NomeFile_TMP, "*", "_")
NomeFile_TMP = Replace(NomeFile_TMP, "?", "_")
NomeFile_TMP = Replace(NomeFile_TMP, "Chr(34)", "_")
NomeFile_TMP = Replace(NomeFile_TMP, "<", "_")
NomeFile_TMP = Replace(NomeFile_TMP, ">", "_")
NomeFile_TMP = Replace(NomeFile_TMP, "|", "_")
NomeFile = NomeFile_TMP & ".pdf"
'NomeFile = agente.Item(i).Text & ".pdf"
printReport "RP01", destPath, NomeFile
'ActiveDocument.GetApplication.Sleep 1000
Set NomeReports= fv
reportFile = "C:\Documents and Settings\ricpet\Documenti\EPM\Report\"& NomeReports.Item(i).Text &".pdf"
'*********************************************************************************commentato invio email automatico ******************************
set val=ActiveDocument.Fields("EMAIL").GetPossibleValues
for j=0 to 10
MAIL_TO=val.Item(j).Text
'MAIL_CC=val2.Item(j).Text
SENDFILE=reportFile
Set objEmail = CreateObject("CDO.Message")
Set objConf = objEmail.Configuration
Set objFlds = objConf.Fields
With objFlds
'---------------------------------------------------------------------
' dettagli server SMTP
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 0
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 0
.Update
'---------------------------------------------------------------------
End With
strSubject = "REPORT : " & ActiveDocument.Fields("FIELD").getpossiblevalues(1).item(0).text
if strSubject ="" then
strSubject = "REPORT : " & ActiveDocument.Fields("FIELD").getpossiblevalues(1).item(0).text
End if
strMsg = "************ MESSAGGIO GENERATO AUTOMATICAMENTE - Non rispondere a questo indirizzo. Per info non rompete i ****************** "
'"<h1>This is some sample message html.</h1>"
if strMsg = "" then
strMsg = "************ MESSAGGIO GENERATO AUTOMATICAMENTE - non rispondere a questo indirizzo. Per info non rompete i ****************** "
End if
objEmail.To = "EMAIL"'MAIL_TO ' Destinatario
objEmail.Cc = "EMAIL2"
'objEmail.BCC = "EMAIL3"
ica.it" ' Mittente
objEmail.Subject = strSubject
objEmail.HTMLBody = strMsg
objEmail.AddAttachment SENDFILE
msgbox("send file")
objEmail.Send
ActiveDocument.GetApplication.Sleep 2000
Set objFlds = Nothing
Set objConf = Nothing
Set objEmail = Nothing
next
next
ActiveDocument.ClearAll "false"
end if
Msgbox("Invio effettuato con successo")
ActiveDocument.ClearAll "true"
End Sub