A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Macro Help



 
 
Thread Tools Display Modes
  #1  
Old April 12th, 2010, 06:27 PM posted to microsoft.public.excel.misc
Dan Wood
external usenet poster
 
Posts: 51
Default Macro Help

My code is as follows:-

Sub SendEmail()
Dim Email As String, Subj As String
Dim Msg As String, URL As String
Email = Range("A5")
For Each c In Range("D730")
If c.Value = 0 Then
SySname = c.Offset(, -3).Value
Subj = SySname


Msg = ""
Msg = Msg & "Hi" & Cells(ActiveCell.Row, 6) & "," & vbCrLf & vbCrLf &
"Your AS400 password is due to expire on the above mentioned system. Please
log on and change your password" & vbCrLf & vbCrLf & "Once you have done this
please update the spreadsheet to reflect the new password, and the date it
was changed."


'Replace spaces with %20 (hex)
Subj = Application.WorksheetFunction.Substitute(Subj, " ", "%20")
Msg = Application.WorksheetFunction.Substitute(Msg, " ", "%20")


'Replace carriage returns with %0D%0A (hex)
Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A")


'Create the URL
URL = "mailto:" & Email & "?subject=" & Subj & "&body=" & Msg


'Execute the URL (start the email client)
ShellExecute O&, vbNullString, URL, vbNullString, vbNullString,
vbNormalFocus


'Wait two seconds before sending keystrokes
'Application.Wait (Now + TimeValue("0:00:02"))
'Application.SendKeys "%s"


End If
Next

However, when i try to run the script it flags up an error in the
ShellExecute part and i cannot figure out why.

Any help much appreciated
  #2  
Old April 12th, 2010, 06:38 PM posted to microsoft.public.excel.misc
Jim Thomlinson
external usenet poster
 
Posts: 2,641
Default Macro Help

Check out this code as a way to send emails without security warnings.

http://www.rondebruin.nl/cdo.htm
--
HTH...

Jim Thomlinson


"Dan Wood" wrote:

My code is as follows:-

Sub SendEmail()
Dim Email As String, Subj As String
Dim Msg As String, URL As String
Email = Range("A5")
For Each c In Range("D730")
If c.Value = 0 Then
SySname = c.Offset(, -3).Value
Subj = SySname


Msg = ""
Msg = Msg & "Hi" & Cells(ActiveCell.Row, 6) & "," & vbCrLf & vbCrLf &
"Your AS400 password is due to expire on the above mentioned system. Please
log on and change your password" & vbCrLf & vbCrLf & "Once you have done this
please update the spreadsheet to reflect the new password, and the date it
was changed."


'Replace spaces with %20 (hex)
Subj = Application.WorksheetFunction.Substitute(Subj, " ", "%20")
Msg = Application.WorksheetFunction.Substitute(Msg, " ", "%20")


'Replace carriage returns with %0D%0A (hex)
Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A")


'Create the URL
URL = "mailto:" & Email & "?subject=" & Subj & "&body=" & Msg


'Execute the URL (start the email client)
ShellExecute O&, vbNullString, URL, vbNullString, vbNullString,
vbNormalFocus


'Wait two seconds before sending keystrokes
'Application.Wait (Now + TimeValue("0:00:02"))
'Application.SendKeys "%s"


End If
Next

However, when i try to run the script it flags up an error in the
ShellExecute part and i cannot figure out why.

Any help much appreciated

  #3  
Old April 12th, 2010, 08:31 PM posted to microsoft.public.excel.misc
Dan Wood
external usenet poster
 
Posts: 51
Default Macro Help

Thanks for the advice but i don't really want to take that route as this
spreadsheet is going to be used as a template for lots of different users to
have to monitor passwords expiring.

The aim is for it to pick up the email address from cell A5.

Any ideas on what i need to change?

Thanks
  #4  
Old April 14th, 2010, 04:33 PM posted to microsoft.public.excel.misc
Ron de Bruin
external usenet poster
 
Posts: 2,861
Default Macro Help

See
http://www.rondebruin.nl/mail/oebody.htm

I think you forgot to copy the function

--

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



"Dan Wood" wrote in message ...
Thanks for the advice but i don't really want to take that route as this
spreadsheet is going to be used as a template for lots of different users to
have to monitor passwords expiring.

The aim is for it to pick up the email address from cell A5.

Any ideas on what i need to change?

Thanks

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:52 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.