VBA Code hangs on Outlook Send?

shophoney

Active Member
Joined
Jun 16, 2014
Messages
281
Hi,

Below is my code and it works. But I use the NEW OUTLOOK. The only way i can send the email is to kill the Legacy version of outlook?? Then the email quickly send but if i try to run it again i have to do the same steps killing the app.

Is this a problem with the new outlook?

Sub Financal_Dashoard_Email()

Dim rng As Range
Dim rng2 As Range
Dim rng3 As Range
Dim rng4 As Range
Dim rng5 As Range
Dim rng6 As Range
Dim rng7 As Range
Dim rng8 As Range

Dim OutApp As Object
Dim OutMail As Object
Dim StrBody As String

StrBody = "Hello Team," & "<br>" & "<br>" & _
"Please note NET INCOME is subject to change as not all payables have been entered." & "<br><br>"


Set rng = Nothing
On Error Resume Next
'Only the visible cells in the selection
'Set rng = Selection.SpecialCells(xlCellTypeVisible)
'You can also use a fixed range if you want
Set rng = Sheets("Financal Dashoard").Range("A2:D99").SpecialCells(xlCellTypeVisible)
Set rng2 = Sheets("Financal Dashoard").Range("F1:K99").SpecialCells(xlCellTypeVisible)
Set rng3 = Sheets("Financal Dashoard").Range("O1:Q99").SpecialCells(xlCellTypeVisible)
Set rng4 = Sheets("Financal Dashoard").Range("S1:Y99").SpecialCells(xlCellTypeVisible)
Set rng5 = Sheets("Financal Dashoard").Range("AA1:AE99").SpecialCells(xlCellTypeVisible)
Set rng6 = Sheets("Financal Dashoard").Range("AG1:AK99").SpecialCells(xlCellTypeVisible)
Set rng7 = Sheets("Financal Dashoard").Range("AM1:AS199").SpecialCells(xlCellTypeVisible)
Set rng8 = Sheets("Financal Dashoard").Range("AU1:AU1").SpecialCells(xlCellTypeVisible)

On Error GoTo 0

If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If

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

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next



With OutMail
.To = "gOD@gOD.COM"
'.CC = "G=EGS-IND-SC-Managers" & ";" & Cells(5, 2)
.BCC = ""
.Subject = Format(Now, "ddd MMM dd/yy") & " - Financal Dashoard"
.HTMLBody = StrBody & RangetoHTML(rng) & RangetoHTML(rng2) & _
RangetoHTML(rng3) & RangetoHTML(rng4) & RangetoHTML(rng5) & _
RangetoHTML(rng6) & RangetoHTML(rng7) & RangetoHTML(rng8)
'.Attachments.Add ActiveWorkbook.FullName
'.Display 'or use .Display
.Send
End With
On Error GoTo 0

With Application
.EnableEvents = True
.ScreenUpdating = True
End With

Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Specifically what is "new Outlook" and what is "Legacy version"?

How do you know it is hanging on the Send, instead of some earlier statement?

I am not sure about your specific question but I don't think Outlook is very friendly about having two versions installed at the same time. Why do you keep the legacy version installed and running?
 
Upvote 0
I don’t use both versions. But the api is part of the windows library. Outlook and office have new apps in the last few months.

It hangs till I kill the app with the previous version of Outlook being called. I’ve done some googling and I’ve noticed other people making the same comment about function calls and Microsoft newer version of Outlook.

If I was to guess, I think there isn’t an API for the new version of Outlook to be called
 
Upvote 0

Forum statistics

Threads
1,215,097
Messages
6,123,076
Members
449,094
Latest member
mystic19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top