Copy a Word document that has text and pictures into the body of an - Microsoft Community


i writing vba code to open word document, make body of outlook message , send list of addresses in excel file.  put button on excel spreadsheet , put the code see below into "on click".

it works far sending out messages text word document, fails include picture .

how can code put in complete contents of word document?

private sub commandbutton1_click()

dim outapp object
dim outmail object
dim integer
dim greeting string

myfname = "c:\users\wayne\desktop\testfile.docx"

set wordapp = createobject("word.application")
set worddoc = wordapp.documents.open(myfname, , true)
body = worddoc.content

worddoc.close ' close document
wordapp.quit ' close word application
set wrddoc = nothing
set wrdapp = nothing
if cells(1, 5) = "" then
cells(1, 5).interior.colorindex = 3
msgbox "error -- not have subject line in cell e1"
cells(1, 5).interior.colorindex = 0
exit sub
end if

for = 2 sheets("sheet1").range("d" & rows.count).end(xlup).row

if cells(i, 2) = "" , cells(i, 3) = "" then
greeting = "dear music lover"
end if

if not cells(i, 1) = "" , not cells(i, 3) = "" then
greeting = ("dear " + cells(i, 1).value + " " + cells(i, 3).value)
end if

if cells(i, 1) = "" , not cells(i, 2) = "" then
greeting = ("dear " + cells(i, 2).value)
end if

body = replace(body, "-salutation-", greeting)
dim maddress string
dim msubject string
maddress = cells(i, 4).value
msubject = cells(1, 5).value

    set outapp = createobject("outlook.application")
    set outmail = outapp.createitem(0)
    outmail
        .to = maddress
        .cc = ""
        .bcc = ""
        .subject = msubject
        .body = body
        .send
    end with
body = replace(body, greeting, "-salutation-")
msgbox greeting
next i

end sub



Office / Unknown/other / Microsoft Office Programming / Office 2016



Comments

Popular posts from this blog

Planner Comments erratic behaviour - Microsoft Community

How to modify and disable a RSS Feed into Yammer - Microsoft Community

Little Red circle with number on top of the OneDrive icon oi the mac - Microsoft Community