Code is Workbook Specific?

Anne Troy

MrExcel MVP
Joined
Feb 18, 2002
Messages
2,632
Office Version
  1. 365
Platform
  1. Windows
Why would this code work perfectly in one workbook and not at all in another? I changed the ranges to add to the body to be named ranges, but even after reverting back to cell references, I get NO message body. The funny thing is that on the code below, I could not seem to get it to add an Outlook signature. However, when I run the code in workbook 2, it creates NO message body but DOES add my Outlook signature.

Bizarro. Any ideas? Thanks!

Code:
Sub SendMeOut()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim cell As Range
    Dim strbody As String


    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")

    On Error GoTo cleanup
          Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            With OutMail
                .To = Range("'Dashboard'!D3").Text
                .CC = Range("'Dashboard'!D4").Text & ";" & Range("'Dashboard'!D5").Text & Range("progemail").Text
                .BCC = Range("'Dashboard'!D6").Text
                
                .Subject = "Harbortouch POS Order Update: " & Range("merchantname").Text & " " & Range("merchantmid").Text
                .Body = Range("'Email Text'!$C$16").Text & Chr(10) & Chr(10) & _
                Range("'Email Text'!$C$18").Text & Chr(10) & Chr(10) & _
                Range("'Email Text'!$C$20").Text & Chr(10) & Chr(10) & _
                Range("'Email Text'!$C$21").Text & Chr(10) & Chr(10) & _
                Range("'Email Text'!$C$22").Text & Chr(10) & Chr(10) & _
                Range("'Email Text'!$C$23").Text & Chr(10) & Chr(10)
                
                .Display  'Or use Send

End With
            On Error GoTo 0
  Set OutMail = Nothing
        
cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Thanks, Andrew.

You know, I'm NOT a coder. Really, I'm not. But somehow I got this job here at this company, thinking I'm gonna be programming their POS systems. Lo and behold, it's a new division so everything is changing every day and I'm making little Excel applications (they're amazed by hyperlink buttons), reports and such (easy to blow them away with buttons and colors), and find myself developing more and more after all these years.

Now, you've taught me something I should have known. Remove the error trap and you find the error. Duh. I've known it from before, but forgot.

I found the issue, but don't know why it was an issue before I used named ranges because it made me find the line that errored and I found a bad named range (even tho it wouldn't run right with regular cell refs either, who knows?).

But I'm not into what was wrong so much as I'm into making it right.

Thanks a ton! It's workin'!
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,183
Members
452,893
Latest member
denay

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