vba - activating a MailMerge from excel -
i still quite new vba, best come on own. used macro recorder in word vba code mailmerge excel spreadsheet, , tied key binding ("^%o"). use sendkeys excel activate mailmerge.
here relevant excel code open word , activate mailmerge. need find "dear" , insert field recipients name excel. ^f through {right} sendkeys. again better way make happen, new know how yet. have excel sendkeys word "^%o" activating mailmerge. have sleeps there slow down code hoping find messing up.
' open word doc. run macro import mailing list / send emails. set wordapp = createobject("word.application") wordapp.documents.open filename:="path word doc" wordapp.visible = true sleep 10000 appactivate "word doc" sleep 500 sendkeys "^f", true sleep 500 sendkeys "dear", true sleep 500 sendkeys "~", true sleep 500 sendkeys "{escape}", true sleep 500 sendkeys "{right}", true sleep 500 sendkeys "{right}", true sleep 500 sendkeys "^%o", true sleep 500
here word code put names after "dear" , send emails. add field "mr" curser position, , import mailing list. send emails list of emails excel.
sub sendemails() ' ' macro1 macro ' ' activedocument.mailmerge.maindocumenttype = wdformletters activedocument.mailmerge.opendatasource name:= _ "path excel spreadsheet" _ , confirmconversions:=false, readonly:=false, linktosource:=true, _ addtorecentfiles:=false, passworddocument:="", passwordtemplate:="", _ writepassworddocument:="", writepasswordtemplate:="", revert:=false, _ format:=wdopenformatauto, connection:= _ "provider=microsoft.ace.oledb.12.0;user id=admin;data source=path excel;mode=read;extended properties=""hdr=yes;imex=1;"";jet oledb:system database="""";jet oledb:registry path="""";jet oledb:engine t" _ , sqlstatement:="select * `email_list$`", sqlstatement1:="", subtype _ :=wdmergesubtypeaccess activedocument.mailmerge.fields.add range:=selection.range, name:="mr" activedocument.mailmerge .destination = wdsendtoemail .mailaddressfieldname = "email" .mailsubject = "subject" .suppressblanklines = true .datasource .firstrecord = wddefaultfirstrecord .lastrecord = wddefaultlastrecord end '.execute pause:=false end end sub
the weird problem running when run excel macro not import correctly. not sort of error not find fields needed excel spreadsheet. when activate word macro myself (even pressing keybinding) imports perfectly. why this, , how can fix it? not looking rework code right now. need works. go , upgrade code new knowledge after making work.
any appreciated.
Comments
Post a Comment