Public Sub SendMail ()
Dim Objaccount as Object
Dim objapp as Object ' Outlook.Application
' If not Checkdata Then
' Exit Sub
' End If
‘
' If MsgBox (Shtmessage.range ("A1"). Value, vbYesNo + vbexclamation) <> vbyes Then
' Exit Sub
' End If
Set objapp = GetObject ("", "Outlook.Application")
If objApp.Session.accounts.Count > 1 Then
Frmaccounts.show vbmodal
If Val (FrmAccounts.lstAccounts.Tag) > 0 Then
Set Objaccount = ObjApp.Session.accounts.Item (Val (FRMACCOUNTS.LSTACCOUNTS.TAG))
Else
Exit Sub
End If
Else
Set Objaccount = ObjApp.Session.accounts.Item (1)
End If
Dim strpath as String
Dim OBJWB as Workbook
' strpath = environ$ ("TEMP") & "\test.xlsm"
' Thisworkbook.savecopyas strpath
Dim Endrow
Dim rowindex as Integer
Endrow = Sheet24.range ("a65536"). End (Xlup). Row
MsgBox Endrow
For rowindex = 1 to Endrow
' Determine if the project name is empty
If Sheet24.cells (rowindex, 1) = "Then
Exit for
End If
Dim objMailItem as Object ' MailItem
Set objMailItem = Objapp.createitem (0)
objmailitem.to = "[Email protected]"
objmailitem.cc = ""
Objmailitem.subject = "Hello World"
Objmailitem.body = "This is a test mail"
ObjMailItem.Attachments.Add exceltowordtopdf (rowindex)
Objmailitem.display
' Objmailitem.send
Next
' Dim objMailItem as Object ' MailItem
‘
' Set objMailItem = Objapp.createitem (0)
‘
' objmailitem.to = ' [email protected] '
' objmailitem.cc = ' "
' Objmailitem.subject = ' Hello World '
' Objmailitem.body = ' This is a test mail '
"' ObjMailItem.Attachments.Add strpath
‘
' Objmailitem.display
"' Objmailitem.send
‘
' MsgBox ' success! ", vbinformation
End Sub
Sub TestFunc () ' defines a string-type parameter s
Dim s
s = "abc"
MsgBox Len (s)
MsgBox Application.ActiveWorkbook.path
' MsgBox exceltowordtopdf ("My Files") ' Returns a string ' return value '
End Sub
Function exceltowordtopdf (rowindex as Integer)
Dim Wddoc, Newpdfpath, Currentpath, filename
Currentpath = Application.ActiveWorkbook.path & "\"
Newpdfpath = Currentpath & "Files\"
filename = Sheet24.cells (rowindex, 1) & ". pdf"
Set Wddoc = CreateObject (Currentpath & "Template.docx") ' Open Word
WdDoc.Range.Find.Execute findtext:= "{1}", replacewith:= "title---test-replage", replace:=1 ' replace replaces 1 once, 2 replaces all
WdDoc.Range.Find.Execute findtext:= "{2}", replacewith:= "test----2"
If Dir (Newpdfpath) = "Then
MkDir (Newpdfpath)
End If
Wddoc.exportasfixedformat Newpdfpath & filename, 17 ' wdexportformatpdf is
Wddoc.close
Set Wddoc = Nothing
exceltowordtopdf = newpdfpath & filename
End Function
VBA-------------VBA export Word to PDF email