VBA-------------VBA export Word to PDF email

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.