Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-31-2008, 09:30 PM
KisH \(Tihomir\)
 
Posts: n/a
excel macro mail send

Hello,
I'm using this vb macro code for sending mail.
---------------------------------------------------------------
Sub mailto_Selection()
Dim Email As String, Subj As String, cell As Range
Dim response As Variant
Dim msg As String, url As String
Email = "" 'create list below
Subj = "Family Newsletter"
msg = "Here needs to be named range from excel(some text)"
'-- Create the URL

For Each cell In Selection
Email = Email & cell.Text & "; "
Next cell

url = "mailto:" & Email & "?subject=" & Subj & "&body=" _
& Replace(msg, Chr(10), "/" & vbCrLf & "\")
url = Left(url, 2025) 'was successful with 2025 , not with 2045
'-- Execute the URL (start the email client)
ActiveWorkbook.FollowHyperlink (url)
Application.Wait (Now + TimeValue("0:00:10"))
Application.SendKeys "%s"

End Sub
-------------------------------------------------------------------------

Problem is that I don't know how to add named range(text) from excel to mail
body.
Ex.
In sheet1 I have text:
Bla bla bla
Bl bl bl
B b b
This text is named as named range "txt".
So, in this line of code " msg = "Here needs to be named range from
excel(some text)" ",
msg needs to have value of named range "txt".

How to do that?

Thank you!



Reply With Quote
  #2 (permalink)  
Old 09-01-2008, 08:11 AM
Per Jessen
 
Posts: n/a
Re: excel macro mail send

Hi

Substitute the "msg=..." line with the code below:

For Each cell in Range("txt")
Msg=Msg & cell.Value
Next

Regards,
Per

"KisH (Tihomir)" <kish89MAKNI@gmail.com> skrev i meddelelsen
news:g9ev1d$leh$1@localhost.localdomain...
> Hello,
> I'm using this vb macro code for sending mail.
> ---------------------------------------------------------------
> Sub mailto_Selection()
> Dim Email As String, Subj As String, cell As Range
> Dim response As Variant
> Dim msg As String, url As String
> Email = "" 'create list below
> Subj = "Family Newsletter"
> msg = "Here needs to be named range from excel(some text)"
> '-- Create the URL
>
> For Each cell In Selection
> Email = Email & cell.Text & "; "
> Next cell
>
> url = "mailto:" & Email & "?subject=" & Subj & "&body=" _
> & Replace(msg, Chr(10), "/" & vbCrLf & "\")
> url = Left(url, 2025) 'was successful with 2025 , not with 2045
> '-- Execute the URL (start the email client)
> ActiveWorkbook.FollowHyperlink (url)
> Application.Wait (Now + TimeValue("0:00:10"))
> Application.SendKeys "%s"
>
> End Sub
> -------------------------------------------------------------------------
>
> Problem is that I don't know how to add named range(text) from excel to
> mail body.
> Ex.
> In sheet1 I have text:
> Bla bla bla
> Bl bl bl
> B b b
> This text is named as named range "txt".
> So, in this line of code " msg = "Here needs to be named range from
> excel(some text)" ",
> msg needs to have value of named range "txt".
>
> How to do that?
>
> Thank you!
>
>
>


Reply With Quote
  #3 (permalink)  
Old 09-01-2008, 10:38 AM
KisH \(Tihomir\)
 
Posts: n/a
Re: excel macro mail send


"Per Jessen" <per.jessen@mail.dk> wrote in message
news:eqEZoHADJHA.5196@TK2MSFTNGP04.phx.gbl...
> Hi
>
> Substitute the "msg=..." line with the code below:
>
> For Each cell in Range("txt")
> Msg=Msg & cell.Value
> Next



Hello,
Thanks for your help but I got this error on your code:

Run-time error '1004':
Application-defined or object-defined error

I'm using Excel 2007


Reply With Quote
  #4 (permalink)  
Old 09-01-2008, 12:49 PM
Nayab
 
Posts: n/a
Re: excel macro mail send

On Sep 1, 2:38*pm, "KisH \(Tihomir\)" <kish89MA...@gmail.com> wrote:
> "Per Jessen" <per.jes...@mail.dk> wrote in message
>
> news:eqEZoHADJHA.5196@TK2MSFTNGP04.phx.gbl...
>
> > Hi

>
> > Substitute the "msg=..." line with the code below:

>
> > For Each cell in Range("txt")
> > * *Msg=Msg & cell.Value
> > Next

>
> Hello,
> Thanks for your help but I got this error on your code:
>
> Run-time error '1004':
> Application-defined or object-defined error
>
> I'm using Excel 2007


I checked it and the solution suggested is fine. However I get an
error 1004 when I try to access a named range which does not exist. So
check the name of the named range you are using.
Reply With Quote
  #5 (permalink)  
Old 09-01-2008, 12:51 PM
KisH \(Tihomir\)
 
Posts: n/a
Re: excel macro mail send


"Nayab" <nayabaz@gmail.com> wrote in message
news:9446ccea-d26c-4389-98e5-c0247e05c479@k37g2000hsf.googlegroups.com...
On Sep 1, 2:38 pm, "KisH \(Tihomir\)" <kish89MA...@gmail.com> wrote:
> "Per Jessen" <per.jes...@mail.dk> wrote in message
>
> news:eqEZoHADJHA.5196@TK2MSFTNGP04.phx.gbl...
>
> > Hi

>
> > Substitute the "msg=..." line with the code below:

>
> > For Each cell in Range("txt")
> > Msg=Msg & cell.Value
> > Next

>
> Hello,
> Thanks for your help but I got this error on your code:
>
> Run-time error '1004':
> Application-defined or object-defined error
>
> I'm using Excel 2007


I checked it and the solution suggested is fine. However I get an
error 1004 when I try to access a named range which does not exist. So
check the name of the named range you are using.


Reply With Quote
  #6 (permalink)  
Old 09-01-2008, 12:54 PM
Per Jessen
 
Posts: n/a
Re: excel macro mail send

Try this one

For Each cell In Range("txt").Cells
msg = msg & cell.Value
Next

Regards,
Per

"KisH (Tihomir)" <kish89MAKNI@gmail.com> skrev i meddelelsen
news:g9gd6f$sb8$1@localhost.localdomain...
>
> "Per Jessen" <per.jessen@mail.dk> wrote in message
> news:eqEZoHADJHA.5196@TK2MSFTNGP04.phx.gbl...
>> Hi
>>
>> Substitute the "msg=..." line with the code below:
>>
>> For Each cell in Range("txt")
>> Msg=Msg & cell.Value
>> Next

>
>
> Hello,
> Thanks for your help but I got this error on your code:
>
> Run-time error '1004':
> Application-defined or object-defined error
>
> I'm using Excel 2007
>


Reply With Quote
  #7 (permalink)  
Old 09-01-2008, 12:54 PM
KisH \(Tihomir\)
 
Posts: n/a
Re: excel macro mail send


"Nayab" <nayabaz@gmail.com> wrote in message
news:9446ccea-d26c-4389-98e5-c0247e05c479@k37g2000hsf.googlegroups.com...
On Sep 1, 2:38 pm, "KisH \(Tihomir\)" <kish89MA...@gmail.com> wrote:
>. So
>check the name of the named range you are using.


Thanks i checked and now code works fine, but i have another problem.
Ex.
A B C
1 text1
2 text2
3 text3
4

Result in email body is text1text2text2.
What do I need to do so I can get in email body:
text1
text2
text3

Thanks.


Reply With Quote
  #8 (permalink)  
Old 09-01-2008, 12:59 PM
Per Jessen
 
Posts: n/a
Re: excel macro mail send

This should do it:

For Each cell In Range("txt").Cells
If msg <> "" Then
msg = msg & vbLf & cell.Value
Else
msg = cell.Value
End If
Next

Regards,
Per

"KisH (Tihomir)" <kish89MAKNI@gmail.com> skrev i meddelelsen
news:g9gl5e$tlb$1@localhost.localdomain...
>
> "Nayab" <nayabaz@gmail.com> wrote in message
> news:9446ccea-d26c-4389-98e5-c0247e05c479@k37g2000hsf.googlegroups.com...
> On Sep 1, 2:38 pm, "KisH \(Tihomir\)" <kish89MA...@gmail.com> wrote:
>>. So
>>check the name of the named range you are using.

>
> Thanks i checked and now code works fine, but i have another problem.
> Ex.
> A B C
> 1 text1
> 2 text2
> 3 text3
> 4
>
> Result in email body is text1text2text2.
> What do I need to do so I can get in email body:
> text1
> text2
> text3
>
> Thanks.
>


Reply With Quote
  #9 (permalink)  
Old 09-01-2008, 01:02 PM
KisH \(Tihomir\)
 
Posts: n/a
Re: excel macro mail send


"Per Jessen" <per.jessen@mail.dk> wrote in message
news:%23z1LvlCDJHA.3908@TK2MSFTNGP04.phx.gbl...
> Try this one
>
> For Each cell In Range("txt").Cells
> msg = msg & cell.Value
> Next
>


Huh same result, everything in one row in mail body.
Maybe problem is somwhere here:
url = "mailto:" & Email & "?subject=" & Subj & "&body=" _
& Replace(msg, Chr(10), "/" & vbCrLf & "\")


Reply With Quote
  #10 (permalink)  
Old 09-01-2008, 01:07 PM
KisH \(Tihomir\)
 
Posts: n/a
Re: excel macro mail send


"Per Jessen" <per.jessen@mail.dk> wrote in message
news:utD$%23oCDJHA.4436@TK2MSFTNGP02.phx.gbl...
> This should do it:
>
> For Each cell In Range("txt").Cells
> If msg <> "" Then
> msg = msg & vbLf & cell.Value
> Else
> msg = cell.Value
> End If
> Next
>

:(
Now result is text1/\text2/\text3



Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:58 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Credit Card | Credit Card Consolidation | Problem Mortgage | Moneygram | Project cars sale



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114