MailBody = Replace(mailBody, "src=""" & tempFolderName & "/" & attachFile.Name & """", "src=""cid:" & attachFile.Name & """") If InStr(1, mailBody, "src=""" & tempFolderName & "/" & attachFile.Name & """", vbBinar圜ompare) > 0 Then ' if the folder has been found, iterate through the filesįor Each attachFile In fso.GetFolder(Environ("Temp") & Application.PathSeparator & tempFolderName).Files If Left(f.Name, Len(tempFileName) + 1) = tempFileName & "_" Then ' try and find the temporary folder name which would contain any imagesįor Each f In fso.GetFolder(Environ("Temp")).SubFolders ' and the image path is updated to point to the attached image ' if the image is included then the image is attached to the email as a hidden attachment ' checking to see if the files are included in the email as an image (i.e. ' so we need to find the directory, and the loop through each of the files ' tempFileName followed by the _files in the local language (e.g. ' if the html contains images, then they will be stored in a directory called clear the signature and any images in the signature)ĭo While > 0 ' clear the content of the email and remove all attachments (i.e. ' display the email so that any images display correctly Set outlookMail = outlookApp.CreateItem(olMailItem) MailBody = fso.OpenTextFile(Environ("Temp") & Application.PathSeparator & tempFileName & ".tmp", 1).ReadAll ' read the html from the temp directory using fso SingleDoc.Close SaveChanges:=wdDoNotSaveChanges SingleDoc.SaveAs2 FileName:=Environ("Temp") & Application.PathSeparator & tempFileName & ".tmp", FileFormat:=wdFormatFilteredHTML ' save the generated doc as a html file in the temp directory Mm.DataSource.LastRecord = mm.DataSource.ActiveRecord Mm.DataSource.FirstRecord = mm.DataSource.ActiveRecord ' use mailmerge to create a new document for one record (defined by mm.DataSource.ActiveRecord) ' only create an email if there is a valid addressa and the row is not marked as to be ignored If InStr(1, df.Value, vbTextCompare) > 0 Then Select Case Asc(LCase(Mid(df.Name, i, 1)))įieldName = fieldName & LCase(Mid(df.Name, i, 1)) ' clean up the provided field name by running through the name letter by letter and adding only letters to the variable fieldName ' run through the fields to check if a valid email address is provided in any of the "to", "cc" or "bcc" fields (valid address = contains an also detect if the row is marked to be ignored Select Case MsgBox("MailMerge to email will proceed for " & IIf(recordCount 0 ' Give the user an opportunity to abort, and also the option to save the emails in drafts, or send immediately Macro will Exit", vbOKOnly + vbCritical, "Error") = vbOK Then Exit Sub If MsgBox("Cannot find any active / valid / not to be ignored records. Mm.DataSource.ActiveRecord = wdNextRecord If mm.DataSource.ActiveRecord = lastRecordNum Then ' counting more than 50 records takes too long ' if the lastRecordNum is less than 50 we assume some may have been deselected so we count only the active records LastRecordNum = mm.DataSource.ActiveRecord Mm.DataSource.ActiveRecord = wdLastRecord ' set lastRecordNum to the number of the last active record (reached using wdLastRecord Macro will exit.", vbOKOnly + vbCritical, "Error") = vbOK Then Exit Sub If MsgBox("Mailmerge not set up for active document - cannot perform mailmerge. ' check for the mail merge state being that of a mail merge ready to go ' identify the mail merge of the active document Tick the check boxes next to the two libraries and press OK. ' To add them, use the "Tools" menu and select "References". ' "Microsoft Outlook xx.x Object Library" (replace xx.x with version number) and "Microsoft Scripting Runtime" ' This Macro requires you to add the following libraries: ' Please share freely while retaining attribution
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |