Excel Email Lock up

jcbaggett16

New Member
Joined
Feb 14, 2024
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Please help, I have it attaching to email if outlook is open. If its not open it locks up excel and will not allow outlook to open automatically or manually.

Sub PDF()
ChDir "C:\Users\...\Desktop\New folder"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\...\Desktop\New folder\Transition " & Range("H2").Text


Dim OutLookApp As Object

On Error Resume Next

Set OutLookApp = GetObject(, "Outlook.Application")
On Error GoTo 0

If OutLookApp Is Nothing Then
Set OutLookApp = CreateObject("Outlook.Application")



Dim OutLookMailItem As Object
Dim myAttachments As Object

Set OutLookMailItem = OutLookApp.CreateItem(0)
Set myAttachments = OutLookMailItem.Attachments

With OutLookMailItem
.To = ""
.Subject = ""
.Body = ""
myAttachments.Add "C:\Users\...\Desktop\New folder\Transition " & Range("H2").Text & ".pdf"
'.send
.Display
End With

Set OutLookMailItem = Nothing
Set OutLookApp = Nothing
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Add the following line of code to your macro ... as the FIRST line of code :

VBA Code:
Shell ("OUTLOOK")
 
Upvote 0
Awesome, simple enough. Is there a way to make it not open up an extra email window if its already open?
 
Upvote 0
Try the following ...

VBA Code:
Shell ("OUTLOOK")
    With GetObject(, "Outlook.Application")
        .ActiveWindow.WindowState = 1   ' olMinimized = 1
    End With


Be certain to include, under TOOLS / REFERENCES : Microsoft Outlook 12 Object Library
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,239
Members
452,621
Latest member
Laura_PinksBTHFT

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