dwarek

Board Regular
Joined
Jul 15, 2016
Messages
79
Hello everyone
i have developed to send a email via outlook the code seems to be fine ,but i just have small problem , i have to print numeric and alpha numeric value from the cell but my code doesn't allow to do that, it shows error. the code is working fine when i use alphabets in the cell but when is use numeric or alpha-numeric value then it doesn't work please help me out in this. Below i have mentioned my code , i need to print numeric value from "str" and alpha numeric from "funid"
many thanks in advance
Private Sub CommandButton1_Click()
Dim str As String
Dim we As Worksheet
Set we = Worksheets("sam")
Range("A2").Select
While Not ActiveCell = ""
Mail_To = ActiveCell.Offset(0, 0)
Mail_Subject = "testing"
Mail_Voting = ActiveCell.Offset(0, 4)
str = ActiveCell.Offset(0, 3)
funid = ActiveCell.Offset(0, 2)

Set myolapp = CreateObject("Outlook.Application")
Set myitem = myolapp.CreateItem(olMailItem)
With myitem


.VotingOptions = Mail_Voting
.To = Mail_To
.Body = "Hello" + " " + str + " " + funid + " " + vbNewLine + we.Cells(1, 1)
.Subject = "confirmation mail"





.display
End With

ActiveCell.Offset(1, 0).Select
Wend



End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I have never tried to use Excel VBA to send emails, but I have done lots of VBA.
One thing that stuck out to me was the following line:
Code:
[COLOR=#333333].Body = "Hello" + " " + str + " " + funid + " " + vbNewLine + we.Cells(1, 1)[/COLOR]
When building stings in VBA, the ampersand is typically used to concatenate your strings, not the plus sign. So try changing it like this and see if it helps:
Code:
[COLOR=#333333].Body = "Hello" & " " & str & " " & funid & " " & vbNewLine & we.Cells(1, 1)[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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