Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default email conditions

Hello everyone.
I am currently using the code below when assigned to a form button to e-mail
off a workbook. Over the course of using my system different worksheets are
added to the workbook. Does anyone know of any way in which i can change the
e-mail address if the Wb contains a certain worksheet? e.g If workbook
contains "Wksht1" or "Wksht2" then send to OR/AND if
Workbook contains "wksht 3" or "Wksht 4" then send to
. If
there is any way that can be added to the code below you will be a lifesaver.
VB is not my first language and it's getting me in strife! Thanks in
advance, Andrew bt

Dim wb As Workbook
Set wb = ActiveWorkbook
If Val(Application.Version) = 12 Then
If wb.FileFormat = 51 And wb.HasVBProject = True Then
MsgBox "There is VBA code in this xlsx file, there will be no
VBA code in the file you send." & vbNewLine & _
"Save the file first as xlsm and then try the macro
again.", vbInformation
Exit Sub
End If
End If
On Error Resume Next
wb.SendMail ", _
"Test e-mail"
On Error GoTo 0
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default email conditions

Hi andrewbt

You can use this in your code

On Error Resume Next
If SheetExists("wksht 3") = True Then
wb.SendMail ", _
"Test e-mail"
Else
wb.SendMail ", _
"Test e-mail"
End If
On Error GoTo 0



Copy this function also in the module

Function SheetExists(SName As String, _
Optional ByVal wb As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If wb Is Nothing Then Set wb = ThisWorkbook
SheetExists = CBool(Len(wb.Sheets(SName).Name))
End Function



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"andrewbt" wrote in message ...
Hello everyone.
I am currently using the code below when assigned to a form button to e-mail
off a workbook. Over the course of using my system different worksheets are
added to the workbook. Does anyone know of any way in which i can change the
e-mail address if the Wb contains a certain worksheet? e.g If workbook
contains "Wksht1" or "Wksht2" then send to OR/AND if
Workbook contains "wksht 3" or "Wksht 4" then send to
. If
there is any way that can be added to the code below you will be a lifesaver.
VB is not my first language and it's getting me in strife! Thanks in
advance, Andrew bt

Dim wb As Workbook
Set wb = ActiveWorkbook
If Val(Application.Version) = 12 Then
If wb.FileFormat = 51 And wb.HasVBProject = True Then
MsgBox "There is VBA code in this xlsx file, there will be no
VBA code in the file you send." & vbNewLine & _
"Save the file first as xlsm and then try the macro
again.", vbInformation
Exit Sub
End If
End If
On Error Resume Next
wb.SendMail ", _
"Test e-mail"
On Error GoTo 0
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default email conditions

Ron you are a life saver yet again, if you ever want the favour returning and
need any help with php, asp, JavaScript, Flash/ActionScript or any thing like
that then drop me a line at i might be able to help, seen
as your excel stuff as answered my prayers on plenty of occasions. ( as you
can tell i'm not a fan of VB ).
Thanks
"Ron de Bruin" wrote:

Hi andrewbt

You can use this in your code

On Error Resume Next
If SheetExists("wksht 3") = True Then
wb.SendMail ", _
"Test e-mail"
Else
wb.SendMail ", _
"Test e-mail"
End If
On Error GoTo 0



Copy this function also in the module

Function SheetExists(SName As String, _
Optional ByVal wb As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If wb Is Nothing Then Set wb = ThisWorkbook
SheetExists = CBool(Len(wb.Sheets(SName).Name))
End Function



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"andrewbt" wrote in message ...
Hello everyone.
I am currently using the code below when assigned to a form button to e-mail
off a workbook. Over the course of using my system different worksheets are
added to the workbook. Does anyone know of any way in which i can change the
e-mail address if the Wb contains a certain worksheet? e.g If workbook
contains "Wksht1" or "Wksht2" then send to OR/AND if
Workbook contains "wksht 3" or "Wksht 4" then send to
. If
there is any way that can be added to the code below you will be a lifesaver.
VB is not my first language and it's getting me in strife! Thanks in
advance, Andrew bt

Dim wb As Workbook
Set wb = ActiveWorkbook
If Val(Application.Version) = 12 Then
If wb.FileFormat = 51 And wb.HasVBProject = True Then
MsgBox "There is VBA code in this xlsx file, there will be no
VBA code in the file you send." & vbNewLine & _
"Save the file first as xlsm and then try the macro
again.", vbInformation
Exit Sub
End If
End If
On Error Resume Next
wb.SendMail ", _
"Test e-mail"
On Error GoTo 0
End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Macro how to create email link for the email addresses in aRange or Selection Satish[_2_] Excel Worksheet Functions 8 December 28th 09 03:30 PM
Countif Conditions - Use of conditions that vary by cell value JonTarg Excel Discussion (Misc queries) 1 May 30th 08 01:21 PM
2 Conditions + Sum of a colum matching those conditions Jeffa Excel Worksheet Functions 5 June 8th 07 12:14 AM
shade cells based on conditions - i have more than 3 conditions Mo2 Excel Worksheet Functions 3 March 30th 07 07:19 AM
How to multiple conditions to validate more than 2 conditions to . Bhuvana Govind Excel Worksheet Functions 1 January 28th 05 07:07 PM


All times are GMT +1. The time now is 11:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"