Sending Outlook mail using Excel VBA

%3CLINGO-SUB%20id%3D%22lingo-sub-197308%22%20slang%3D%22en-US%22%3ESending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197308%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20VBA%20macro%20working%20-%20mostly%20-%20that%20copies%20part%20of%20an%20Excel%20worksheet%20and%20pastes%20(with%20formatting)%20into%20a%20new%20Outlook%20email%2C%20between%20surrounding%20text%20blocks.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETrouble%20is%2C%20the%20macro%20is%20not%20reliable.%20%26nbsp%3BWe%20take%20as%20a%20given%20that%20Outlook%20is%20running.%20%26nbsp%3BThe%20macro%20fails%20if%20it%20is%20not%2C%20but%20that's%20acceptable%20for%20the%20environment%20the%20macro%20is%20used%20in.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20macro%20works%20fine%20if%20Outlook%20is%20running%20with%20no%20windows%20open%20other%20than%20the%20inbox.%20%26nbsp%3BIt%20always%20fails%20if%20another%20email%20is%20open%2C%20whether%20the%20Inbox%20or%20that%20email%20is%20frontmost.%20%26nbsp%3BIn%20the%20case%20where%20an%20email%20is%20already%20open%2C%20the%20new%20email%20is%20created%20with%20the%20proper%20subject%20and%20such%20but%20the%20clipboard%20gets%20pasted%20into%20the%20email%26nbsp%3Bthat%20was%26nbsp%3Balready%20open%20before%20the%20macro%20was%20called.%20%26nbsp%3B%5Bcorrection%5D%20%26nbsp%3BThe%20only%20scenario%20that%20works%20as%20intended%20is%20when%20Outlook%20is%20running%2C%20not%20minimized%2C%20and%20no%20document%20windows%20open.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20can%20I%20make%20sure%20the%20active%20selection%20point%20in%20Outlook%20is%20placed%20into%20the%20macro-created%20email%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere's%20my%20code.%20%26nbsp%3BNot%20shown%20is%20the%20Excel%20code%20that%20has%20already%20copied%20the%20desired%20content%20to%20the%20clipboard.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EDim%20strbody1%20As%20String%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EDim%20strbody2%20As%20String%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EDim%20objMail%20As%20Outlook.MailItem%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EDim%20objInsp%20As%20Inspector%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EDim%20objDoc%20As%20Word.Document%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EDim%20objSel%20As%20Word.Selection%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EWith%20Application%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E.ScreenUpdating%20%3D%20False%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E.EnableEvents%20%3D%20False%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EEnd%20With%3CBR%20%2F%3E%3CBR%20%2F%3Estrbody1%20%3D%20%E2%80%9CLeading%20text%20appears%20before%20Excel%20table%E2%80%9C%3CBR%20%2F%3Estrbody2%20%3D%20%E2%80%9CFollowing%20text%20appears%20after%20Excel%20table%E2%80%9C%3CBR%20%2F%3E%3CBR%20%2F%3E'%20Opens%20email%20and%20adds%20subject%20and%20text%3CBR%20%2F%3E%3CBR%20%2F%3ESet%20objMail%20%3D%20Outlook.Application.CreateItem(0)%3CBR%20%2F%3EWith%20objMail%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%20%26nbsp%3B%26nbsp%3B%20%3C%2FSPAN%3E.Display%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%20%26nbsp%3B%26nbsp%3B%20%3C%2FSPAN%3E.Subject%20%3D%20%E2%80%9CMy%20Subject%E2%80%9D%3CBR%20%2F%3EEnd%20With%3CBR%20%2F%3E%3CBR%20%2F%3E'Pastes%20table%20to%20email%3CBR%20%2F%3E%3CBR%20%2F%3ESet%20objInsp%20%3D%20objMail.GetInspector%3CBR%20%2F%3EIf%20objInsp.EditorType%20%3D%20olEditorWord%20Then%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESet%20objDoc%20%3D%20objInsp.WordEditor%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESet%20objWord%20%3D%20objDoc.Application%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESet%20objSel%20%3D%20objWord.Selection%3CBR%20%2F%3EWith%20objSel%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%20%26nbsp%3B%20%3C%2FSPAN%3E.InsertAfter%20vbCr%20%26amp%3B%20strbody2%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%20%20%26nbsp%3B%20%3C%2FSPAN%3E.HomeKey%20unit%3A%3DwdStory%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%20%20%26nbsp%3B%20%3C%2FSPAN%3E.PasteAndFormat%20(wdformatorginalformatting)%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%20%20%3C%2FSPAN%3E.EndOf%20unit%3A%3DwdStory%2C%20Extend%3A%3DwdMove%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%20%26nbsp%3B%20%3C%2FSPAN%3E.HomeKey%20unit%3A%3DwdStory%3CBR%20%2F%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%20%26nbsp%3B%20%3C%2FSPAN%3E.InsertAfter%20strbody1%20%26amp%3B%20vbCr%3CBR%20%2F%3EEnd%20With%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3ESet%20objMail%20%3D%20Nothing%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-197308%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20%26amp%3B%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ENeed%20Help%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-201949%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-201949%22%20slang%3D%22en-US%22%3E%3CP%3EWayne-%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHow%20Exciting!!%26nbsp%3B%20Glad%20you%20were%20able%20to%20get%20it%20working!%26nbsp%3B%20I'll%20have%20to%20remember%20that%20for%20future%20reference!%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECheers!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-201939%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-201939%22%20slang%3D%22en-US%22%3E%3CP%3EOK%2C%20here%20is%20the%20solution%20that%20is%20working.%20%26nbsp%3BThe%20critical%20change%20was%20to%20construct%20the%20text%20for%20the%20email%2C%20including%20calling%20the%20RangeToHtml%20function%2C%20before%20going%20to%20Outlook.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECode%20prior%20to%20this%20point%20selects%20and%20copies%20the%20desired%20content%20on%20the%20source%20worksheet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E'Formatted%20text%20to%20go%20in%20email%20before%20table%20from%20Excel%3C%2FP%3E%3CP%3Estrbody1%20%3D%20%22%3CSPAN%20style%3D%22font-size%3A10pt%3Bfont-family%3AArial%3B%22%3E%20Text%20before%20table%20%3C%2FSPAN%3E%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E'%3CSPAN%3EText%20to%20go%20in%20email%20%3C%2FSPAN%3E%3CEM%3Eafter%3C%2FEM%3E%20table%3C%2FP%3E%3CP%3Estrbody2%20%3D%20%22%3CSPAN%20style%3D%22font-size%3A10pt%3Bfont-family%3AArial%3B%22%3E%3CBR%20%2F%3E%20Text%20after%20table%20%3C%2FSPAN%3E%22%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3ETable%20%3D%20RangetoHTML(MyHTMLRng)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3BDim%20OutApp%20As%20Object%3C%2FP%3E%3CP%3E%26nbsp%3B%20Dim%20OutMail%20As%20Object%3C%2FP%3E%3CP%3E%26nbsp%3B%20Dim%20OutlookOpened%20As%20Boolean%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20OutlookOpened%20%3D%20False%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20On%20Error%20Resume%20Next%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20OutApp%20%3D%20GetObject(%2C%20%22Outlook.Application%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20If%20OutApp%20Is%20Nothing%20Then%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20OutApp%20%3D%20CreateObject(%22Outlook.Application%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20OutlookOpened%20%3D%20True%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20End%20If%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3BSet%20OutMail%20%3D%20OutApp.CreateItem(0)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20On%20Error%20Resume%20Next%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20With%20OutMail%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Display%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Subject%20%3D%20%22My%20Subject%22%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Signature%20%3D%20OutMail.HTMLBody%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.HTMLBody%20%3D%20strbody1%20%26amp%3B%20Table%20%26amp%3B%20strbody2%20%26amp%3B%20Signature%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20End%20With%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20On%20Error%20GoTo%200%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20OutMail%20%3D%20Nothing%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20OutApp%20%3D%20Nothing%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3EApplication.ScreenUpdating%20%3D%20True%26nbsp%3B%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFunction%20RangetoHTML(MyHTMLRng)%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20fso%20As%20Object%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20ts%20As%20Object%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20TempFile%20As%20String%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20TempWB%2C%20wbName%2C%20wbThis%20As%20Workbook%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20rngNew%20As%20Range%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20x%20As%20Integer%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20TempFile%20%3D%20Environ%24(%22temp%22)%20%26amp%3B%20%22%2F%22%20%26amp%3B%20Format(Now%2C%20%22dd-mm-yy%20h-mm-ss%22)%20%26amp%3B%20%22.htm%22%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B'Create%20a%20new%20workbook%20to%20paste%20the%20source%20table%20data%20into%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20TempWB%20%3D%20Workbooks.Add(1)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20With%20TempWB.Sheets(1)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Cells(1).PasteSpecial%20Paste%3A%3D8%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Cells(1).PasteSpecial%20xlPasteValues%2C%20%2C%20False%2C%20False%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Cells(1).PasteSpecial%20xlPasteFormats%2C%20%2C%20False%2C%20False%3C%2FP%3E%3CP%3E'%20This%20next%20bit%20deletes%20a%20blank%20row%20in%20the%20table%20if%20one%20is%20found.%20%26nbsp%3BThere%20cannot%20be%20more%20than%20one%2C%20so%20the%20loop%20exits%20if%20one%20is%20found.%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BFor%20myRow%20%3D%201%20To%20100%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20If%20Len(.Cells(myRow%2C%201).Value)%20%26lt%3B%201%20Then%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B.Cells(myRow%2C%201).EntireRow.Delete%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Exit%20For%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20End%20If%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Next%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BApplication.CutCopyMode%20%3D%20False%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20On%20Error%20Resume%20Next%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.DrawingObjects.Visible%20%3D%20True%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.DrawingObjects.Delete%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20On%20Error%20GoTo%200%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BEnd%20With%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B'Publish%20the%20sheet%20to%20a%20htm%20file%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20With%20TempWB.PublishObjects.Add(%20_%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20SourceType%3A%3DxlSourceRange%2C%20_%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Filename%3A%3DTempFile%2C%20_%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Sheet%3A%3DTempWB.Sheets(1).Name%2C%20_%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Source%3A%3DTempWB.Sheets(1).UsedRange.Address%2C%20_%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20HtmlType%3A%3DxlHtmlStatic)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Publish%20(False)%20'True%20will%20replace%2C%20rather%20than%20insert%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20End%20With%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B'Read%20all%20data%20from%20the%20htm%20file%20into%20RangetoHTML%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20fso%20%3D%20CreateObject(%22Scripting.FileSystemObject%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20ts%20%3D%20fso.GetFile(TempFile).OpenAsTextStream(1%2C%20-2)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20RangetoHTML%20%3D%20ts.ReadAll%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ts.Close%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20RangetoHTML%20%3D%20Replace(RangetoHTML%2C%20%22align%3Dcenter%20x%3Apublishsource%3D%22%2C%20_%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22align%3Dleft%20x%3Apublishsource%3D%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B'Close%20TempWB%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20TempWB.Close%20savechanges%3A%3DFalse%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B'Delete%20the%20htm%20file%20we%20used%20in%20this%20function%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Kill%20TempFile%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BSet%20ts%20%3D%20Nothing%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20fso%20%3D%20Nothing%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20TempWB%20%3D%20Nothing%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3EEnd%20Function%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-201149%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-201149%22%20slang%3D%22en-US%22%3E%3CP%3EWe've%20come%20up%20with%20a%20solution%20that's%20working!%20%26nbsp%3BIt's%20not%20much%20different%20than%20what%20is%20above%20but%20different%20enough%20I%20guess%2C%20because%20it's%20working.%20%26nbsp%3BI'll%20post%20the%20details%20after%20a%20bit%20more%20testing%20but%20I%20wanted%20to%20let%20you%20know%20that%20we%20can%20all%20%22stand%20down%22%20for%20now.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-200077%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-200077%22%20slang%3D%22en-US%22%3E%3CP%3ECode%20prior%20to%20this%20selects%20and%20copies%20the%20relevant%20range%20in%20Excel%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CBLOCKQUOTE%3E%3CP%3EDim%20OutApp%20As%20Object%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20OutMail%20As%20Object%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20OutlookOpened%20As%20Boolean%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20OutlookOpened%20%3D%20False%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20On%20Error%20Resume%20Next%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20OutApp%20%3D%20GetObject(%2C%20%22Outlook.Application%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20If%20OutApp%20Is%20Nothing%20Then%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20OutApp%20%3D%20CreateObject(%22Outlook.Application%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20OutlookOpened%20%3D%20True%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20End%20If%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E'Create%20a%20dummy%20email%20and%20close%20it%20without%20saving%3C%2FSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3ESet%20OutMail%20%3D%20OutApp.CreateItem(0)%3C%2FP%3E%3CP%3EWith%20OutMail%3C%2FP%3E%3CP%3E.Subject%20%3D%20%22Test%22%3C%2FP%3E%3CP%3E.Close%201%3C%2FP%3E%3CP%3EEnd%20With%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E'Text%20before%20table%3C%2FP%3E%3CP%3Estrbody1%20%3D%20%22%20Some%20leading%20text%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E'Text%20after%20table%3C%2FP%3E%3CP%3Estrbody2%20%3D%20%22%20%3C%2FP%3E%3CP%3E%20Some%20trailing%20text%20%22%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BSet%20OutMail%20%3D%20OutApp.CreateItem(0)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20On%20Error%20Resume%20Next%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20With%20OutMail%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Display%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Signature%20%3D%20OutMail.HTMLBody%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Subject%20%3D%20%22My%20eMail%22%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.HTMLBody%20%3D%20strbody1%20%26amp%3B%20RangetoHTML(MyHTMLRng)%20%26amp%3B%20strbody2%20%26amp%3B%20Signature%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20End%20With%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20On%20Error%20GoTo%200%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20OutMail%20%3D%20Nothing%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20If%20OutlookOpened%20Then%20OutApp.Quit%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20OutApp%20%3D%20Nothing%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFunction%20RangetoHTML(MyHTMLRng)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20fso%20As%20Object%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20ts%20As%20Object%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20TempFile%20As%20String%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20TempWB%20As%20Workbook%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BTempFile%20%3D%20Environ%24(%22temp%22)%20%26amp%3B%20%22%2F%22%20%26amp%3B%20Format(Now%2C%20%22dd-mm-yy%20h-mm-ss%22)%20%26amp%3B%20%22.htm%22%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B'Copy%20the%20range%20and%20create%20a%20new%20workbook%20to%20past%20the%20data%20in%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20TempWB%20%3D%20Workbooks.Add(1)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20With%20TempWB.Sheets(1)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Cells(1).PasteSpecial%20Paste%3A%3D8%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Cells(1).PasteSpecial%20xlPasteValues%2C%20%2C%20False%2C%20False%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Cells(1).PasteSpecial%20xlPasteFormats%2C%20%2C%20False%2C%20False%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Cells(1).Select%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Application.CutCopyMode%20%3D%20False%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20On%20Error%20Resume%20Next%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.DrawingObjects.Visible%20%3D%20True%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.DrawingObjects.Delete%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20On%20Error%20GoTo%200%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20End%20With%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B'Publish%20the%20sheet%20to%20a%20htm%20file%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20With%20TempWB.PublishObjects.Add(%20_%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20SourceType%3A%3DxlSourceRange%2C%20_%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Filename%3A%3DTempFile%2C%20_%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Sheet%3A%3DTempWB.Sheets(1).Name%2C%20_%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Source%3A%3DTempWB.Sheets(1).UsedRange.Address%2C%20_%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20HtmlType%3A%3DxlHtmlStatic)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Publish%20(False)%20'False%20will%20insert%2C%20rather%20than%20replace%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20End%20With%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B'Read%20all%20data%20from%20the%20htm%20file%20into%20RangetoHTML%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20fso%20%3D%20CreateObject(%22Scripting.FileSystemObject%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20ts%20%3D%20fso.GetFile(TempFile).OpenAsTextStream(1%2C%20-2)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20RangetoHTML%20%3D%20ts.ReadAll%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ts.Close%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20RangetoHTML%20%3D%20Replace(RangetoHTML%2C%20%22align%3Dcenter%20x%3Apublishsource%3D%22%2C%20_%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22align%3Dleft%20x%3Apublishsource%3D%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B'Close%20TempWB%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20TempWB.Close%20savechanges%3A%3DFalse%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B'Delete%20the%20htm%20file%20we%20used%20in%20this%20function%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Kill%20TempFile%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BSet%20ts%20%3D%20Nothing%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20fso%20%3D%20Nothing%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20TempWB%20%3D%20Nothing%3C%2FP%3E%3CP%3EEnd%20Function%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-200053%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-200053%22%20slang%3D%22en-US%22%3E%3CP%3EWayne-%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECan%20you%20please%20send%20me%20your%20updated%20VBA%20code%20with%20the%20RangeToHTML%20portion%20incorporated%3F%26nbsp%3B%20Specifically%20the%20email%20portion%20of%20the%20code.%26nbsp%3B%20I%20believe%20your%20issue%20revolves%20around%20the%20method%20the%20code%20is%20incorporating%20the%20email%20signature%20portion%20(Either%20way%20it%20would%20be%20helpful%20to%20use%20the%20code%20when%20testing).%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-200036%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-200036%22%20slang%3D%22en-US%22%3E%3CP%3EChecking%20Windows%2C%20Excel%20and%20Outlook%20versions%20now...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOffice%202010%20on%20Windows%207%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20we%20have%20everything%20working%20fine%20content-wise%20including%20the%20user's%20custom%20email%20signature.%20%26nbsp%3BWe're%20stuck%20on%20the%20open%20emails%20problem.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAdditional%20detail%3A%20%26nbsp%3BThe%20problem%20is%20when%20the%20most%20recently%20created%20email%20is%20still%20open.%20%26nbsp%3BIf%20the%20last%20email%20to%20be%20created%20is%20closed%20before%20the%20macro%20runs%2C%20I%20believe%20it%20all%20works%20fairly%20reliably.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-200035%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-200035%22%20slang%3D%22en-US%22%3E%3CP%3EWayne-%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20can't%20replicate%20your%20issue%20in%20the%20below%20scenario.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENote%20my%20example%20did%20not%20include%20an%20email%20signature....%20is%20this%20absolutely%20necessary%3F%26nbsp%3B%20Or%20could%20you%20have%20a%20text%20signature%20like%20this%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EMatt%20Mickle%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EX%20Company%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EContact%20Info.....%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Eetc..%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F35266iEA6D12E2308A49B4%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22MultipleAppsOpen.png%22%20title%3D%22MultipleAppsOpen.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-200021%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-200021%22%20slang%3D%22en-US%22%3E%3CP%3ESad%20news.%20%26nbsp%3BMy%20tester%20finally%20had%20time%20to%20resume%20this%20project%2C%20and%20reports%20that%20the%20code%20above%20fails%20like%20our%20earlier%20efforts.%20%26nbsp%3BNeither%20works%20if%26nbsp%3Banother%20mail%20document%20is%20already%20open.%20%26nbsp%3BBoth%20work%20fine%20if%20no%20other%20doc%20is%20open.%20%26nbsp%3BWe%20had%20included%20a%20loop%20to%20close%20open%20documents%20before%20this%20executes%2C%20and%20I%20believe%20it%20solved%20the%20problem%2C%20but%20it's%20not%20a%20practical%20solution%20given%20the%20workflow%20of%20the%20users.%20%26nbsp%3BIt's%20be%20a%20huge%20nuisance%20to%20close%20a%20bunch%20of%20emails.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOn%20the%20upside%2C%20it%20was%20fairly%20easy%20to%20modify%20the%20code%20above%26nbsp%3Bto%20insert%20the%20text%20blocks%20on%20either%20side%20of%20the%20table%20and%20to%20keep%20the%20user's%20email%20signature%20block.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'd%20be%20curious%20to%20see%20if%20you%20can%20replicate%20the%20open-email%20doc%20problem%20on%20your%20end.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-199589%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-199589%22%20slang%3D%22en-US%22%3E%3CP%3EWayne-%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EJust%20wanted%20to%20follow%20up%20and%20see%20if%20you%20were%20able%20to%20get%20the%20macro%20fixed.%26nbsp%3B%20If%20not%20I'm%20happy%20to%20do%20some%20additional%20troubleshooting.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197989%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197989%22%20slang%3D%22en-US%22%3EThanks%20a%20million%20for%20this.%20We'll%20look%20it%20over%20and%20see%20if%20we%20can%20get%20it%20working%20for%20us.%20The%20approach%20sounds%20promising%2C%20The%20Word%20editor%20trick%20was%20impressive%20but%20we%20just%20haven't%20been%20able%20to%20iron%20out%20the%20bugs%2C%20In%20the%20meanwhile%2C%20enjoy%20the%20weekend!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197967%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197967%22%20slang%3D%22en-US%22%3E%3CP%3ETypically%20SendKeys%20should%20be%20used%20as%20a%20last%20alternative%20as%20it%20can%20behave%20unexpectedly.%26nbsp%3B%20Ironically%2C%20the%20code%20that%20you%20need%20to%20use%20was%20also%20created%20by%20Ron%20De%20Bruin.%26nbsp%3B%20It%20turns%20a%20range%20into%20HTML.%26nbsp%3B%20THat%20way%20you%20can%20just%20put%20the%20HTML%20in%20the%20email%20rather%20than%20having%20to%20use%20MS%20Word%20as%20an%20intermediary.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20is%20the%20original%20website%20link%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwww.rondebruin.nl%2Fwin%2Fs1%2Foutlook%2Fbmail2.htm%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.rondebruin.nl%2Fwin%2Fs1%2Foutlook%2Fbmail2.htm%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20is%20his%20code%20that%20I%20have%20modified%20to%20work%20for%20my%20needs.%26nbsp%3B%20I%20believe%20this%20should%20do%20what%20you%20want.%26nbsp%3B%20If%20it%20doesn't%20work%20I%20can%20look%20at%20another%20project%20where%20I%20did%20something%20similar.%20%3A%3C%2FP%3E%0A%3CPRE%3ESub%20CreateAnHTMLEmail()%0A%0A%20%20%20%20'Alter%20Send%20Email%20Sub%20Procedure%20Details%20in%20order%0A%20%20%20%20'To%20Modify%20Subject%2C%20Recipients...etc...%0A%20%20%20%20'The%20range%20put%20in%20this%20Sub%20is....the%20one%20that%20will%20be%0A%20%20%20%20'put%20into%20the%20email...%20i.e.%20This%20puts%20A1%3AG21%20in%20the%20email%0A%20%20%20%20Call%20SendEmail(Sheets(%22Sheet1%22).Range(%22A1%3AG21%22))%0A%20%20%20%20%0AEnd%20Sub%0A%0A%0ASub%20SendEmail(MyHTMLRng%20As%20Range)%0A%0A%20%20%20%20Dim%20OutApp%20As%20Object%0A%20%20%20%20Dim%20OutMail%20As%20Object%0A%20%20%20%20Dim%20OutlookOpened%20As%20Boolean%0A%0A%20%20%20%20OutlookOpened%20%3D%20False%0A%20%20%20%20On%20Error%20Resume%20Next%0A%20%20%20%20Set%20OutApp%20%3D%20GetObject(%2C%20%22Outlook.Application%22)%0A%20%20%20%20If%20OutApp%20Is%20Nothing%20Then%0A%20%20%20%20%20%20%20%20Set%20OutApp%20%3D%20CreateObject(%22Outlook.Application%22)%0A%20%20%20%20%20%20%20%20OutlookOpened%20%3D%20True%0A%20%20%20%20End%20If%0A%20%20%20%20Set%20OutMail%20%3D%20OutApp.CreateItem(0)%0A%20%20%20%20%0A%20%20%20%20On%20Error%20Resume%20Next%0A%20%20%20%20With%20OutMail%0A%20%20%20%20%20%20%20%20.To%20%3D%20%22name%40abc.com%22%0A%20%20%20%20%20%20%20%20.cc%20%3D%20%22fox%40test.com%3B%20otherperson%40test.com%22%0A%20%20%20%20%20%20%20%20.Subject%20%3D%20%22My%20Subject%20Line%22%0A%20%20%20%20%20%20%20%20.htmlbody%20%3D%20RangetoHTML(MyHTMLRng)%0A%20%20%20%20%20%20%20%20.Display%20%20'allows%20email%20to%20be%20displayed%20and%20checked%20before%20manually%20sending%20it%0A%20%20%20%20%20%20%20%20'.Send%20'This%20sends%20the%20email%0A%20%20%20%20End%20With%0A%20%20%20%20On%20Error%20GoTo%200%0A%20%20%20%20Set%20OutMail%20%3D%20Nothing%0A%0A%20%20%20%20If%20OutlookOpened%20Then%20OutApp.Quit%0A%20%20%20%20Set%20OutApp%20%3D%20Nothing%0A%20%20%20%20%20%20%20%20%20%20%20%20%0AEnd%20Sub%0A%0AFunction%20RangetoHTML(rng%20As%20Range)%0A'%20Changed%20by%20Ron%20de%20Bruin%2028-Oct-2006%0A'%20Working%20in%20Office%202000-2010%0A%20%20%20%20Dim%20fso%20As%20Object%0A%20%20%20%20Dim%20ts%20As%20Object%0A%20%20%20%20Dim%20TempFile%20As%20String%0A%20%20%20%20Dim%20TempWB%20As%20Workbook%0A%20%0A%20%20%20%20TempFile%20%3D%20Environ%24(%22temp%22)%20%26amp%3B%20%22%2F%22%20%26amp%3B%20Format(Now%2C%20%22dd-mm-yy%20h-mm-ss%22)%20%26amp%3B%20%22.htm%22%0A%20%0A%20%20%20%20'Copy%20the%20range%20and%20create%20a%20new%20workbook%20to%20past%20the%20data%20in%0A%20%20%20%20rng.Copy%0A%20%20%20%20Set%20TempWB%20%3D%20Workbooks.Add(1)%0A%20%20%20%20With%20TempWB.Sheets(1)%0A%20%20%20%20%20%20%20%20.Cells(1).PasteSpecial%20Paste%3A%3D8%0A%20%20%20%20%20%20%20%20.Cells(1).PasteSpecial%20xlPasteValues%2C%20%2C%20False%2C%20False%0A%20%20%20%20%20%20%20%20.Cells(1).PasteSpecial%20xlPasteFormats%2C%20%2C%20False%2C%20False%0A%20%20%20%20%20%20%20%20.Cells(1).Select%0A%20%20%20%20%20%20%20%20Application.CutCopyMode%20%3D%20False%0A%20%20%20%20%20%20%20%20On%20Error%20Resume%20Next%0A%20%20%20%20%20%20%20%20.DrawingObjects.Visible%20%3D%20True%0A%20%20%20%20%20%20%20%20.DrawingObjects.Delete%0A%20%20%20%20%20%20%20%20On%20Error%20GoTo%200%0A%20%20%20%20End%20With%0A%20%0A%20%20%20%20'Publish%20the%20sheet%20to%20a%20htm%20file%0A%20%20%20%20With%20TempWB.PublishObjects.Add(%20_%0A%20%20%20%20%20%20%20%20%20SourceType%3A%3DxlSourceRange%2C%20_%0A%20%20%20%20%20%20%20%20%20Filename%3A%3DTempFile%2C%20_%0A%20%20%20%20%20%20%20%20%20Sheet%3A%3DTempWB.Sheets(1).Name%2C%20_%0A%20%20%20%20%20%20%20%20%20Source%3A%3DTempWB.Sheets(1).UsedRange.Address%2C%20_%0A%20%20%20%20%20%20%20%20%20HtmlType%3A%3DxlHtmlStatic)%0A%20%20%20%20%20%20%20%20.Publish%20(True)%0A%20%20%20%20End%20With%0A%20%0A%20%20%20%20'Read%20all%20data%20from%20the%20htm%20file%20into%20RangetoHTML%0A%20%20%20%20Set%20fso%20%3D%20CreateObject(%22Scripting.FileSystemObject%22)%0A%20%20%20%20Set%20ts%20%3D%20fso.GetFile(TempFile).OpenAsTextStream(1%2C%20-2)%0A%20%20%20%20RangetoHTML%20%3D%20ts.ReadAll%0A%20%20%20%20ts.Close%0A%20%20%20%20RangetoHTML%20%3D%20Replace(RangetoHTML%2C%20%22align%3Dcenter%20x%3Apublishsource%3D%22%2C%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22align%3Dleft%20x%3Apublishsource%3D%22)%0A%20%0A%20%20%20%20'Close%20TempWB%0A%20%20%20%20TempWB.Close%20savechanges%3A%3DFalse%0A%20%0A%20%20%20%20'Delete%20the%20htm%20file%20we%20used%20in%20this%20function%0A%20%20%20%20Kill%20TempFile%0A%20%0A%20%20%20%20Set%20ts%20%3D%20Nothing%0A%20%20%20%20Set%20fso%20%3D%20Nothing%0A%20%20%20%20Set%20TempWB%20%3D%20Nothing%0AEnd%20Function%0A%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197909%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197909%22%20slang%3D%22en-US%22%3E%3CP%3ENuts.%20%26nbsp%3BI%20had%20a%20more%20detailed%20answer%20but%20I%20put%20a%20link%20in%20it%20and%20that%20got%20it%20removed%20as%20spam.%20%26nbsp%3BI've%20asked%20for%20it%20to%20be%20restored.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnyway%2C%3C%2FP%3E%3CP%3E1.%20%26nbsp%3BYes%3C%2FP%3E%3CP%3E2.%20%26nbsp%3BOnly%20as%20a%20way%20to%20get%20the%20Excel%20selection%20into%20an%20email%20with%20format%20retained.%3C%2FP%3E%3CP%3E3.%20%26nbsp%3BYes%2C%20an%20intermediate%20editor%20step%20ONLY%2C%20so%20that%20the%20Excel%20formatting%20is%20not%20lost.%20%26nbsp%3BApparently%20Outlook%20VB%20cannot%20do%20that.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%5Bupdate%5D%20%26nbsp%3BWe're%20getting%20closer.%20%26nbsp%3BWe%20used%20SendKeys%20to%20tab%20forward%20into%20the%20body%20while%20we%20were%20setting%20the%20.Subject%20of%20the%20objMail.%20%26nbsp%3B(Using%20.Body%20to%20add%20text%20causes%20a%20loss%20of%20formatting.)%20%26nbsp%3BWith%20this%20change%2C%20the%20macro%20works%20all%20the%20time%20EXCEPT%20when%3CEM%3E%20the%20last%20created%20email%20is%20open%3C%2FEM%3E.%20%26nbsp%3BI%20find%20this%20bizarre%20but%20by%20trial%20and%20error%20we%20discovered%20that%20closing%20or%20sending%20the%20most-recent%20email%20in%20Outlook%20allows%20the%20macro%20to%20succeed%20even%20if%20%26nbsp%3Bolder%20Outlook%20mail%20windows%20remain%20open.%3C%2FP%3E%3CP%3EI%20tried%20a%20kludge%20to%20open%20and%20then%20close%20a%26nbsp%3Bdummy%26nbsp%3Bemail%20within%20the%20macro%2C%20before%20creating%20the%20desired%20email.%20%26nbsp%3BThis%20sadly%20didn't%26nbsp%3Bwork.%20%26nbsp%3BThere's%20something%20crucial%20about%20actually%20looking%20at%20the%20email%20in%20Outlook%20and%20then%20closing%20it.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197794%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197794%22%20slang%3D%22en-US%22%3E%3CBLOCKQUOTE%3E%3CHR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F37127%22%20target%3D%22_blank%22%3E%40Matt%20Mickle%3C%2FA%3E%26nbsp%3Bwrote%3A%3CBR%20%2F%3E%3CP%3E1.%20If%20possible%20would%20you%20like%20to%20copy%20data%20from%20Excel%20directly%20to%20the%20email%3F%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3CP%3EExactly.%20%26nbsp%3BTrying%20to%20paste%20in%20formatted%20Excel%20cells.%20%26nbsp%3BEvery%20Outlook%20example%20I%20could%20find%20creates%20an%20attachment%20to%20excerpt%20the%20Excel%20selection%2C%20and%20attaches%20that%20to%20the%20email%20in%20Outlook.%20%26nbsp%3BI%20need%20to%20put%20the%20formatted%20Excel%20selection%20directly%20into%20the%20email.%20%26nbsp%3BI%20found%20a%20description%20of%20the%20VBA%20limitation%26nbsp%3Bwith%20Outlook%20that%20prohibits%20this%2C%20and%20that's%20where%20using%20the%20WordEditor%20code%20comes%20in.%20%26nbsp%3BAs%20noted%20earlier%20this%20does%20work%20but%20only%20in%20a%20limited%20set%20of%20circumstances%20(no%20other%20open%20Outlook%20doc).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CBLOCKQUOTE%3E%3CP%3E2.%20Are%20you%20trying%20to%20copy%20a%20table%20from%20word%20to%20the%20email%3F%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3CP%3EUltimately%2C%20no%2C%20I%20have%20no%20need%20for%20Word%20except%20to%20enable%20pasting%20in%20formatted%20Excel%20content.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CBLOCKQUOTE%3E%3CP%3E3.%20Is%20word%20being%20used%20as%20some%20type%20of%20intermediary%3F%26nbsp%3B%20If%20so%20what%20is%20the%20purpose%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3CP%3EYes%2C%20intermediary%20ONLY%2C%20to%20enable%20pasting%20formatted%20Excel%20content%20for%20the%20ultimate%20destination%20-%20an%20Outlook%20email.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFWIW%2C%20I%20found%20some%20code%20here...%3C%2FP%3E%3CP%3E%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwww.datanumen.com%2Fblogs%2Fquickly-close-open-items-except-current-one-outlook%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.datanumen.com%2Fblogs%2Fquickly-close-open-items-except-current-one-outlook%2F%3C%2FA%3E%3C%2FP%3E%3CP%3E...that%20works%20to%20close%20any%20other%20open%20Outlook%20windows%20and%20ultimately%20puts%20all%20the%20text%20in%20the%20right%20place.%20%26nbsp%3BHowever%20my%20tester%20notes%20that%20here%20customers%20signature%20is%20lost%20as%20well%20as%20the%20email%20formatting.%20%26nbsp%3BI%20believe%20the%20Excel%20information%20retains%20its%20format%20but%20I%20can%20check.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197785%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197785%22%20slang%3D%22en-US%22%3E%3CP%3EWayne-%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENo%20problem.%26nbsp%3B%20I'll%20run%20some%20additional%20tests.%26nbsp%3B%20However%2C%20before%20I%20do%2C%20I%20wanted%20to%20ask%20a%20few%20questions%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20see%20MS%20Word%20VBA%20references%20in%20your%20code%20which%20makes%20me%20wonder%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1.%20If%20possible%20would%20you%20like%20to%20copy%20data%20from%20Excel%20directly%20to%20the%20email%3F%3C%2FP%3E%0A%3CP%3E2.%20Are%20you%20trying%20to%20copy%20a%20table%20from%20word%20to%20the%20email%3F%3C%2FP%3E%0A%3CP%3E3.%20Is%20word%20being%20used%20as%20some%20type%20of%20intermediary%3F%26nbsp%3B%20If%20so%20what%20is%20the%20purpose%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20only%20reason%20I%20ask%20about%20these%20items%20is%20because%20there%20is%20a%20way%20to%20copy%20directly%20from%20excel%20and%20maintain%20formatting%2C%20but%20if%20you%20are%20trying%20to%20copy%20the%20table%20from%20word%20then%20the%20code%20will%20be%20different%20of%20course....%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197733%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197733%22%20slang%3D%22en-US%22%3E%3CP%3ESorry%20about%20the%20delay.%20%26nbsp%3BI%20work%20on%20a%20Mac%20but%20this%20code%20has%20to%20be%20tested%20on%20a%20Windows%20machine.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnyway%2C%20the%20.CurrentItem%20attempt%20returned%20a%20%22type%20Mismatch%22%20error.%20%26nbsp%3BMy%20tester%20reports%20that%20.CurrentView%20was%20on%20the%20list%20of%20suggestions%20but%20.CurrentItem%20was%20not.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20second%20attempt%2C%20the%20Dim%20statement%20and%20the%20objInspector%20line%20returned%20an%20error%20%22object%20variable%20or%20with%20block%20variable%20not%20set%22%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197464%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197464%22%20slang%3D%22en-US%22%3E%3CP%3EWayne-%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESorry%20I%20think%20I%20misunderstood%20your%20issue.%26nbsp%3B%20I%20haven't%20fiddled%20around%20with%20Outlook%20VBA%20in%20a%20while%2C%20but%20maybe%20try%20changing%20this%20line%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CSTRONG%3ESet%20objInsp%20%3D%20objMail.GetInspector.CurrentItem%3C%2FSTRONG%3E%3C%2FPRE%3E%0A%3CP%3E%3CSTRONG%3EIf%20that%20doesn't%20work%20try%20these%20two%20modifications%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAdd%20this%20to%20your%20Dim%20Statements%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%20%20%20%20Dim%20outApp%20As%20Outlook.Application%3C%2FPRE%3E%0A%3CP%3EThen%20change%20this%20code%20as%20well%3A%3C%2FP%3E%0A%3CPRE%3ESet%20objInsp%20%3D%20outApp.ActiveExplorer.CurrentItem%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FPRE%3E%0A%3CP%3EIf%20neither%20of%20these%20will%20work.%26nbsp%3B%20Please%20let%20me%20know%20and%20I%20can%20do%20additional%20testing%20to%20try%20and%20replicate%20your%20issue.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197443%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197443%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20familiar%20with%20that%20excellent%20site%2C%20but%20it%20does%20not%20address%20the%20issue%20I'm%20having.%20%26nbsp%3B(Or%20at%20least%20I%20can't%20find%20it.)%20%26nbsp%3BI%20don't%20care%20if%20the%20macro%20fails%20when%26nbsp%3BOutlook%20is%20not%20open.%20%26nbsp%3BThe%20folks%20using%20the%20macro%20use%20Outlook%20all%20day%20long.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197373%22%20slang%3D%22en-US%22%3ERe%3A%20Sending%20Outlook%20mail%20using%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197373%22%20slang%3D%22en-US%22%3E%3CP%3EWayne-%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20order%20to%20avoid%20issues%20you%20can%20first%20check%20to%20see%20if%20Outlook%20is%20open%2C%20like%20shown%20on%20Ron%20De%20Bruin's%20website%20here%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20title%3D%22https%3A%2F%2Fwww.rondebruin.nl%2Fwin%2Fs1%2Foutlook%2Fopenclose.htm%22%20href%3D%22https%3A%2F%2Fwww.rondebruin.nl%2Fwin%2Fs1%2Foutlook%2Fopenclose.htm%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.rondebruin.nl%2Fwin%2Fs1%2Foutlook%2Fopenclose.htm%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3ESub%20TestOutlookIsOpen()%0A%20%20%20%20Dim%20oOutlook%20As%20Object%0A%0A%20%20%20%20On%20Error%20Resume%20Next%0A%20%20%20%20Set%20oOutlook%20%3D%20GetObject(%2C%20%22Outlook.Application%22)%0A%20%20%20%20On%20Error%20GoTo%200%0A%0A%20%20%20%20If%20oOutlook%20Is%20Nothing%20Then%0A%20%20%20%20%20%20%20%20MsgBox%20%22Outlook%20is%20not%20open%2C%20open%20Outlook%20and%20try%20again%22%0A%20%20%20%20Else%0A%20%20%20%20%20%20%20%20'Call%20NameOfYourMailMacro%0A%20%20%20%20End%20If%0AEnd%20Sub%3C%2FPRE%3E%0A%3CP%3EIf%20you%20incorporate%20this%20into%20the%20code%20it%20may%20help%20resolve%20your%20issue.%26nbsp%3B%20If%20you%20still%20have%20issues%2C%20feel%20free%20to%20post%20back%20and%20I%20can%20help%20you%20incorporate%20the%20snippet%20into%20your%20code.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Deleted
Not applicable

I have a VBA macro working - mostly - that copies part of an Excel worksheet and pastes (with formatting) into a new Outlook email, between surrounding text blocks.

 

Trouble is, the macro is not reliable.  We take as a given that Outlook is running.  The macro fails if it is not, but that's acceptable for the environment the macro is used in.

 

The macro works fine if Outlook is running with no windows open other than the inbox.  It always fails if another email is open, whether the Inbox or that email is frontmost.  In the case where an email is already open, the new email is created with the proper subject and such but the clipboard gets pasted into the email that was already open before the macro was called.  [correction]  The only scenario that works as intended is when Outlook is running, not minimized, and no document windows open.

 

How can I make sure the active selection point in Outlook is placed into the macro-created email?

 

Here's my code.  Not shown is the Excel code that has already copied the desired content to the clipboard.

 

 

    Dim strbody1 As String
    Dim strbody2 As String
    Dim objMail As Outlook.MailItem
    Dim objInsp As Inspector
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

strbody1 = “Leading text appears before Excel table“
strbody2 = “Following text appears after Excel table“

' Opens email and adds subject and text

Set objMail = Outlook.Application.CreateItem(0)
With objMail
   .Display
   .Subject = “My Subject”
End With

'Pastes table to email

Set objInsp = objMail.GetInspector
If objInsp.EditorType = olEditorWord Then
    Set objDoc = objInsp.WordEditor
    Set objWord = objDoc.Application
    Set objSel = objWord.Selection
With objSel
  .InsertAfter vbCr & strbody2
  .HomeKey unit:=wdStory
  .PasteAndFormat (wdformatorginalformatting)
  .EndOf unit:=wdStory, Extend:=wdMove
  .HomeKey unit:=wdStory
  .InsertAfter strbody1 & vbCr
End With
End If
Set objMail = Nothing

 

18 Replies
Highlighted

Wayne-

 

In order to avoid issues you can first check to see if Outlook is open, like shown on Ron De Bruin's website here:

 

https://www.rondebruin.nl/win/s1/outlook/openclose.htm

 

Sub TestOutlookIsOpen()
    Dim oOutlook As Object

    On Error Resume Next
    Set oOutlook = GetObject(, "Outlook.Application")
    On Error GoTo 0

    If oOutlook Is Nothing Then
        MsgBox "Outlook is not open, open Outlook and try again"
    Else
        'Call NameOfYourMailMacro
    End If
End Sub

If you incorporate this into the code it may help resolve your issue.  If you still have issues, feel free to post back and I can help you incorporate the snippet into your code.

 

 

 

Highlighted

I'm familiar with that excellent site, but it does not address the issue I'm having.  (Or at least I can't find it.)  I don't care if the macro fails when Outlook is not open.  The folks using the macro use Outlook all day long.

Highlighted

Wayne-

 

Sorry I think I misunderstood your issue.  I haven't fiddled around with Outlook VBA in a while, but maybe try changing this line:

 

Set objInsp = objMail.GetInspector.CurrentItem

If that doesn't work try these two modifications:

 

Add this to your Dim Statements:

 

    Dim outApp As Outlook.Application

Then change this code as well:

Set objInsp = outApp.ActiveExplorer.CurrentItem

If neither of these will work.  Please let me know and I can do additional testing to try and replicate your issue.

 

Highlighted

Sorry about the delay.  I work on a Mac but this code has to be tested on a Windows machine.

 

Anyway, the .CurrentItem attempt returned a "type Mismatch" error.  My tester reports that .CurrentView was on the list of suggestions but .CurrentItem was not.

 

The second attempt, the Dim statement and the objInspector line returned an error "object variable or with block variable not set"

Highlighted

Wayne-

 

No problem.  I'll run some additional tests.  However, before I do, I wanted to ask a few questions

 

I see MS Word VBA references in your code which makes me wonder:

 

1. If possible would you like to copy data from Excel directly to the email?

2. Are you trying to copy a table from word to the email?

3. Is word being used as some type of intermediary?  If so what is the purpose?

 

The only reason I ask about these items is because there is a way to copy directly from excel and maintain formatting, but if you are trying to copy the table from word then the code will be different of course....

 

 

Highlighted

@Matt Mickle wrote:

1. If possible would you like to copy data from Excel directly to the email?

Exactly.  Trying to paste in formatted Excel cells.  Every Outlook example I could find creates an attachment to excerpt the Excel selection, and attaches that to the email in Outlook.  I need to put the formatted Excel selection directly into the email.  I found a description of the VBA limitation with Outlook that prohibits this, and that's where using the WordEditor code comes in.  As noted earlier this does work but only in a limited set of circumstances (no other open Outlook doc).

 

2. Are you trying to copy a table from word to the email?

Ultimately, no, I have no need for Word except to enable pasting in formatted Excel content.

 

3. Is word being used as some type of intermediary?  If so what is the purpose?

 

Yes, intermediary ONLY, to enable pasting formatted Excel content for the ultimate destination - an Outlook email.

 

FWIW, I found some code here...

 https://www.datanumen.com/blogs/quickly-close-open-items-except-current-one-outlook/

...that works to close any other open Outlook windows and ultimately puts all the text in the right place.  However my tester notes that here customers signature is lost as well as the email formatting.  I believe the Excel information retains its format but I can check.

 

Highlighted

Nuts.  I had a more detailed answer but I put a link in it and that got it removed as spam.  I've asked for it to be restored.

 

Anyway,

1.  Yes

2.  Only as a way to get the Excel selection into an email with format retained.

3.  Yes, an intermediate editor step ONLY, so that the Excel formatting is not lost.  Apparently Outlook VB cannot do that.

 

[update]  We're getting closer.  We used SendKeys to tab forward into the body while we were setting the .Subject of the objMail.  (Using .Body to add text causes a loss of formatting.)  With this change, the macro works all the time EXCEPT when the last created email is open.  I find this bizarre but by trial and error we discovered that closing or sending the most-recent email in Outlook allows the macro to succeed even if  older Outlook mail windows remain open.

I tried a kludge to open and then close a dummy email within the macro, before creating the desired email.  This sadly didn't work.  There's something crucial about actually looking at the email in Outlook and then closing it.

Highlighted

Typically SendKeys should be used as a last alternative as it can behave unexpectedly.  Ironically, the code that you need to use was also created by Ron De Bruin.  It turns a range into HTML.  THat way you can just put the HTML in the email rather than having to use MS Word as an intermediary.

 

Here is the original website link: https://www.rondebruin.nl/win/s1/outlook/bmail2.htm

 

Here is his code that I have modified to work for my needs.  I believe this should do what you want.  If it doesn't work I can look at another project where I did something similar. :

Sub CreateAnHTMLEmail()

    'Alter Send Email Sub Procedure Details in order
    'To Modify Subject, Recipients...etc...
    'The range put in this Sub is....the one that will be
    'put into the email... i.e. This puts A1:G21 in the email
    Call SendEmail(Sheets("Sheet1").Range("A1:G21"))
    
End Sub


Sub SendEmail(MyHTMLRng As Range)

    Dim OutApp As Object
    Dim OutMail As Object
    Dim OutlookOpened As Boolean

    OutlookOpened = False
    On Error Resume Next
    Set OutApp = GetObject(, "Outlook.Application")
    If OutApp Is Nothing Then
        Set OutApp = CreateObject("Outlook.Application")
        OutlookOpened = True
    End If
    Set OutMail = OutApp.CreateItem(0)
    
    On Error Resume Next
    With OutMail
        .To = "name@abc.com"
        .cc = "fox@test.com; otherperson@test.com"
        .Subject = "My Subject Line"
        .htmlbody = RangetoHTML(MyHTMLRng)
        .Display  'allows email to be displayed and checked before manually sending it
        '.Send 'This sends the email
    End With
    On Error GoTo 0
    Set OutMail = Nothing

    If OutlookOpened Then OutApp.Quit
    Set OutApp = Nothing
            
End Sub

Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2010
    Dim fso As Object
    Dim ts As Object
    Dim TempFile As String
    Dim TempWB As Workbook
 
    TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
 
    'Copy the range and create a new workbook to past the data in
    rng.Copy
    Set TempWB = Workbooks.Add(1)
    With TempWB.Sheets(1)
        .Cells(1).PasteSpecial Paste:=8
        .Cells(1).PasteSpecial xlPasteValues, , False, False
        .Cells(1).PasteSpecial xlPasteFormats, , False, False
        .Cells(1).Select
        Application.CutCopyMode = False
        On Error Resume Next
        .DrawingObjects.Visible = True
        .DrawingObjects.Delete
        On Error GoTo 0
    End With
 
    'Publish the sheet to a htm file
    With TempWB.PublishObjects.Add( _
         SourceType:=xlSourceRange, _
         Filename:=TempFile, _
         Sheet:=TempWB.Sheets(1).Name, _
         Source:=TempWB.Sheets(1).UsedRange.Address, _
         HtmlType:=xlHtmlStatic)
        .Publish (True)
    End With
 
    'Read all data from the htm file into RangetoHTML
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
    RangetoHTML = ts.ReadAll
    ts.Close
    RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                          "align=left x:publishsource=")
 
    'Close TempWB
    TempWB.Close savechanges:=False
 
    'Delete the htm file we used in this function
    Kill TempFile
 
    Set ts = Nothing
    Set fso = Nothing
    Set TempWB = Nothing
End Function
Highlighted
Thanks a million for this. We'll look it over and see if we can get it working for us. The approach sounds promising, The Word editor trick was impressive but we just haven't been able to iron out the bugs, In the meanwhile, enjoy the weekend!
Highlighted

Wayne-

 

Just wanted to follow up and see if you were able to get the macro fixed.  If not I'm happy to do some additional troubleshooting.

Highlighted

Sad news.  My tester finally had time to resume this project, and reports that the code above fails like our earlier efforts.  Neither works if another mail document is already open.  Both work fine if no other doc is open.  We had included a loop to close open documents before this executes, and I believe it solved the problem, but it's not a practical solution given the workflow of the users.  It's be a huge nuisance to close a bunch of emails.

 

On the upside, it was fairly easy to modify the code above to insert the text blocks on either side of the table and to keep the user's email signature block.

 

I'd be curious to see if you can replicate the open-email doc problem on your end.

Highlighted

Wayne-

 

I can't replicate your issue in the below scenario.

 

Note my example did not include an email signature.... is this absolutely necessary?  Or could you have a text signature like this:

 

Matt Mickle

X Company

Contact Info.....

etc..

 

 

MultipleAppsOpen.png

 

 

Highlighted

Checking Windows, Excel and Outlook versions now...

 

Office 2010 on Windows 7

 

And we have everything working fine content-wise including the user's custom email signature.  We're stuck on the open emails problem.

 

Additional detail:  The problem is when the most recently created email is still open.  If the last email to be created is closed before the macro runs, I believe it all works fairly reliably.

Highlighted

Wayne-

 

Can you please send me your updated VBA code with the RangeToHTML portion incorporated?  Specifically the email portion of the code.  I believe your issue revolves around the method the code is incorporating the email signature portion (Either way it would be helpful to use the code when testing).

Highlighted

Code prior to this selects and copies the relevant range in Excel

 

Dim OutApp As Object

    Dim OutMail As Object

    Dim OutlookOpened As Boolean

    OutlookOpened = False

    On Error Resume Next

    Set OutApp = GetObject(, "Outlook.Application")

    If OutApp Is Nothing Then

        Set OutApp = CreateObject("Outlook.Application")

        OutlookOpened = True

    End If

 

'Create a dummy email and close it without saving      

Set OutMail = OutApp.CreateItem(0)

With OutMail

.Subject = "Test"

.Close 1

End With

         

'Text before table

strbody1 = "<BODY style=font-size:10pt;font-family:Arial; margin-bottom: 0em> Some leading text</BODY>"

 

'Text after table

strbody2 = "<BODY style=font-size:10pt;font-family:Arial; margin-bottom: 0em > <p> Some trailing text </BODY>"

   

    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next

    With OutMail

         .Display

    Signature = OutMail.HTMLBody

         .Subject = "My eMail"

         .HTMLBody = strbody1 & RangetoHTML(MyHTMLRng) & strbody2 & Signature

    End With

    On Error GoTo 0

    Set OutMail = Nothing

 

    If OutlookOpened Then OutApp.Quit

    Set OutApp = Nothing

           

End Sub

 

Function RangetoHTML(MyHTMLRng)

    Dim fso As Object

    Dim ts As Object

    Dim TempFile As String

    Dim TempWB As Workbook

    TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

    'Copy the range and create a new workbook to past the data in

    Set TempWB = Workbooks.Add(1)

    With TempWB.Sheets(1)

        .Cells(1).PasteSpecial Paste:=8

        .Cells(1).PasteSpecial xlPasteValues, , False, False

        .Cells(1).PasteSpecial xlPasteFormats, , False, False

        .Cells(1).Select

        Application.CutCopyMode = False

        On Error Resume Next

        .DrawingObjects.Visible = True

        .DrawingObjects.Delete

        On Error GoTo 0

    End With

    'Publish the sheet to a htm file

    With TempWB.PublishObjects.Add( _

         SourceType:=xlSourceRange, _

         Filename:=TempFile, _

         Sheet:=TempWB.Sheets(1).Name, _

         Source:=TempWB.Sheets(1).UsedRange.Address, _

         HtmlType:=xlHtmlStatic)

        .Publish (False) 'False will insert, rather than replace

    End With

    'Read all data from the htm file into RangetoHTML

    Set fso = CreateObject("Scripting.FileSystemObject")

    Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)

    RangetoHTML = ts.ReadAll

    ts.Close

    RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _

                          "align=left x:publishsource=")

    'Close TempWB

    TempWB.Close savechanges:=False

    'Delete the htm file we used in this function

    Kill TempFile

    Set ts = Nothing

    Set fso = Nothing

    Set TempWB = Nothing

End Function

Highlighted

We've come up with a solution that's working!  It's not much different than what is above but different enough I guess, because it's working.  I'll post the details after a bit more testing but I wanted to let you know that we can all "stand down" for now.

Highlighted

OK, here is the solution that is working.  The critical change was to construct the text for the email, including calling the RangeToHtml function, before going to Outlook.

 

Code prior to this point selects and copies the desired content on the source worksheet.

 

'Formatted text to go in email before table from Excel

strbody1 = "<span style=font-size:10pt;font-family:Arial; margin-bottom: 0px> Text before table </span>"

 

'Text to go in email after table

strbody2 = "<span style=font-size:10pt;font-family:Arial; margin-bottom: 0em <br/> Text after table </span>"

   

Table = RangetoHTML(MyHTMLRng)

 

  Dim OutApp As Object

  Dim OutMail As Object

  Dim OutlookOpened As Boolean

    OutlookOpened = False

    On Error Resume Next

    Set OutApp = GetObject(, "Outlook.Application")

    If OutApp Is Nothing Then

        Set OutApp = CreateObject("Outlook.Application")

        OutlookOpened = True

    End If

   

  Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next

    With OutMail

         .Display

         .Subject = "My Subject"

         Signature = OutMail.HTMLBody

         .HTMLBody = strbody1 & Table & strbody2 & Signature

    End With

    On Error GoTo 0

    Set OutMail = Nothing

    Set OutApp = Nothing

            

Application.ScreenUpdating = True 

End Sub

 

Function RangetoHTML(MyHTMLRng) 

    Dim fso As Object

    Dim ts As Object

    Dim TempFile As String

    Dim TempWB, wbName, wbThis As Workbook

    Dim rngNew As Range

    Dim x As Integer 

    TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

    'Create a new workbook to paste the source table data into 

    Set TempWB = Workbooks.Add(1)

    With TempWB.Sheets(1)

        .Cells(1).PasteSpecial Paste:=8

        .Cells(1).PasteSpecial xlPasteValues, , False, False

        .Cells(1).PasteSpecial xlPasteFormats, , False, False

' This next bit deletes a blank row in the table if one is found.  There cannot be more than one, so the loop exits if one is found.       

        For myRow = 1 To 100

        If Len(.Cells(myRow, 1).Value) < 1 Then

        .Cells(myRow, 1).EntireRow.Delete

        Exit For

        End If

        Next

        Application.CutCopyMode = False

        On Error Resume Next

        .DrawingObjects.Visible = True

        .DrawingObjects.Delete

        On Error GoTo 0   

    End With

    'Publish the sheet to a htm file

    With TempWB.PublishObjects.Add( _

         SourceType:=xlSourceRange, _

         Filename:=TempFile, _

         Sheet:=TempWB.Sheets(1).Name, _

         Source:=TempWB.Sheets(1).UsedRange.Address, _

         HtmlType:=xlHtmlStatic)

        .Publish (False) 'True will replace, rather than insert

    End With

    'Read all data from the htm file into RangetoHTML

    Set fso = CreateObject("Scripting.FileSystemObject")

    Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)

    RangetoHTML = ts.ReadAll

    ts.Close

    RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _

                          "align=left x:publishsource=")

    'Close TempWB

    TempWB.Close savechanges:=False

    'Delete the htm file we used in this function

    Kill TempFile

    Set ts = Nothing

    Set fso = Nothing

    Set TempWB = Nothing      

End Function

Highlighted

Wayne-

 

How Exciting!!  Glad you were able to get it working!  I'll have to remember that for future reference!  

 

Cheers!