BUTTON "O.K."-CANCEL

verluc

Well-known Member
Joined
Mar 1, 2002
Messages
1,451
I have a macro with the following line:
Dim olApp As Object, olMail As Object
Dim rngeAddresses As Range, rngeCell As Range
Set olApp = CreateObject("Outlook.Application")
Set rngeAddresses = Application.InputBox(prompt:="Give a text"
For Each rngeCell In rngeAddresses.Cells
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = rngeCell.Value
I can use the O.K. button,but by press the CANCEL-button,I receive an errormessage on the line : Set rngeAddresses.....
Can somebody give me a solution ?
Many thanks.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try;

<pre/>
Dim olApp As Object, olMail As Object
Dim rngeAddresses As Range, rngeCell As Range

Set olApp = CreateObject("Outlook.Application")

On Error Resume Next
Set rngeAddresses = Application.InputBox(prompt:="Give a text", Type:=8)
If Err Then Exit Sub
On Error GoTo 0

For Each rngeCell In rngeAddresses.Cells
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = rngeCell.Value
Next
</pre>
 
Upvote 0
On 2002-04-29 00:11, Ivan F Moala wrote:
Try;

<pre/>
Dim olApp As Object, olMail As Object
Dim rngeAddresses As Range, rngeCell As Range

Set olApp = CreateObject("Outlook.Application")

On Error Resume Next
Set rngeAddresses = Application.InputBox(prompt:="Give a text", Type:=8)
If Err Then Exit Sub
On Error GoTo 0

For Each rngeCell In rngeAddresses.Cells
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = rngeCell.Value
Next
</pre>
Hi Ivan,

Still a little question.
In this macro I must filled in a range:
exeample : A5 : A20

Is it possible that this macro can filled in automatickly the range.
The range is from A5 to the last row of column A.So I must not each time filled in manualy the range and I still have the possibility to change the range.
Thank for your time.
 
Upvote 0
On 2002-04-29 02:29, verluc wrote:
On 2002-04-29 00:11, Ivan F Moala wrote:
Try;

<pre/>
Dim olApp As Object, olMail As Object
Dim rngeAddresses As Range, rngeCell As Range

Set olApp = CreateObject("Outlook.Application")

On Error Resume Next
Set rngeAddresses = Application.InputBox(prompt:="Give a text", Type:=8)
If Err Then Exit Sub
On Error GoTo 0

For Each rngeCell In rngeAddresses.Cells
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = rngeCell.Value
Next
</pre>
Hi Ivan,

Still a little question.
In this macro I must filled in a range:
exeample : A5 : A20

Is it possible that this macro can filled in automatickly the range.
The range is from A5 to the last row of column A.So I must not each time filled in manualy the range and I still have the possibility to change the range.
Thank for your time.

If I understand you correctly then

<pre/>
Dim olApp As Object, olMail As Object
Dim rngeAddresses As Range, rngeCell As Range

Set olApp = CreateObject("Outlook.Application")

On Error Resume Next
Set rngeAddresses = Range(Range("A5"), Range("A5").End(xlDown))
If Err Then Exit Sub
On Error GoTo 0

For Each rngeCell In rngeAddresses
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = rngeCell.Value
Next
</pre>
 
Upvote 0
On 2002-04-29 02:59, Ivan F Moala wrote:
On 2002-04-29 02:29, verluc wrote:
On 2002-04-29 00:11, Ivan F Moala wrote:
Try;

<pre/>
Dim olApp As Object, olMail As Object
Dim rngeAddresses As Range, rngeCell As Range

Set olApp = CreateObject("Outlook.Application")

On Error Resume Next
Set rngeAddresses = Application.InputBox(prompt:="Give a text", Type:=8)
If Err Then Exit Sub
On Error GoTo 0

For Each rngeCell In rngeAddresses.Cells
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = rngeCell.Value
Next
</pre>
Hi Ivan,

Still a little question.
In this macro I must filled in a range:
exeample : A5 : A20

Is it possible that this macro can filled in automatickly the range.
The range is from A5 to the last row of column A.So I must not each time filled in manualy the range and I still have the possibility to change the range.
Thank for your time.

If I understand you correctly then

<pre/>
Dim olApp As Object, olMail As Object
Dim rngeAddresses As Range, rngeCell As Range

Set olApp = CreateObject("Outlook.Application")

On Error Resume Next
Set rngeAddresses = Range(Range("A5"), Range("A5").End(xlDown))
If Err Then Exit Sub
On Error GoTo 0

For Each rngeCell In rngeAddresses
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = rngeCell.Value
Next
</pre>
Thanks Ivan,that's what I need.
Thanks for your time.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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