Conditional Statement in a "With" Block

MikeG

Well-known Member
Joined
Jul 4, 2004
Messages
845
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
In the macro below, I only want to add an attachment to an email if the variable cur_num is greater than zero. So I tried the If statement shown, but I find that this does not work in the With block.

Could someone help me out.

Thanks,

MikeG


===============================================


With OutMail
.To = a
.CC = b
.BCC = ""
.Subject = c
.body = d
If cur_num > 0 Then
.Attachments.Add ActiveWorkbook.FullName
End If
.display
End With
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
The IF statement should work within the With block.
  • Double check the value of cur_num
  • Make sure the ActiveWorkbook has been saved. An unsaved workbook has no .FullName
 
Upvote 0
The IF statement should work within the With block.
  • Double check the value of cur_num
  • Make sure the ActiveWorkbook has been saved. An unsaved workbook has no .FullName

Thanks - the problem was with the value of cur_num.

Mike
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,735
Members
452,939
Latest member
WCrawford

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