PDA

View Full Version : Modification in the Excel to Outlook mail



Prabhu
05-26-2014, 10:31 AM
Hi All,

I am using the attached macro to send excel sheet thru outlook mail body and am facing problem when the sheet is not exist.

In the attached macro "Sheet 9" send to Mr.SSS(efgh@gmail.com) is not available but it is pasting the previously copied "Sheet1" instead of not coping(should be blank).

Kindly help to modify if the sheet is not exist it should not copy anything.

Regards,

Prabhu

LalitPandey87
06-26-2014, 11:47 AM
In your code there are two email sending code first one is for Sheet1 or Sheet2 and second is for Sheet9 or Sheet2 so what email sending code you want me to check.

Or check this one and add red colred syntax:



Set rng = Nothing
Set rng2 = Nothing
On Error Resume Next






With Sheets("Sheet9")
LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
LC = .Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
Set rng = .Range(.Cells(3, 1), .Cells(LR, LC)).SpecialCells(xlCellTypeVisible)
End With


With Sheets("Sheet2")
LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
LC = .Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
Set rng2 = .Range(.Cells(3, 1), .Cells(LR, LC)).SpecialCells(xlCellTypeVisible)
End With