Selection error

Alexxu

Board Regular
Joined
Aug 9, 2008
Messages
134
hello.
I have this code:
Code:
Sub InsertDate()

    Dim Error As Integer
    On Error GoTo Err
        Selection.InsertDateTime DateTimeFormat:="dd.MM.yyyy", InsertAsField:= _
        False, DateLanguage:=wdRomanian, CalendarType:=wdCalendarWestern, _
        InsertAsFullWidth:=False
       
Err:
        MsgBox "Atentie.Au fost selectate mai multe informatii.Corectati selectia!", vbInformation, "Atentie"
End Sub

When i select multiple items i get un error.Whaty i want is to show me the msgbox error when i get that error.
The code as it is now, pops up the msgbox everytime i insert data.
What should i do?
thanks
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try

Code:
Sub InsertDate()
If Selection.Areas.Count > 1 Then
        MsgBox "Atentie.Au fost selectate mai multe informatii.Corectati selectia!", vbInformation, "Atentie"
Else
        Selection.InsertDateTime DateTimeFormat:="dd.MM.yyyy", InsertAsField:= _
        False, DateLanguage:=wdRomanian, CalendarType:=wdCalendarWestern, _
        InsertAsFullWidth:=False
End If
End Sub
 
Upvote 0
I get un error wich reffers to the .Areas.
I forgeten to say that this code was fit to work in a ms word module.:(
 
Upvote 0
Untested:

Code:
Sub InsertDate()

    Dim Error As Integer
    On Error GoTo Err
        Selection.InsertDateTime DateTimeFormat:="dd.MM.yyyy", InsertAsField:= _
        False, DateLanguage:=wdRomanian, CalendarType:=wdCalendarWestern, _
        InsertAsFullWidth:=False
        Exit Sub
       
Err:
        MsgBox "Atentie.Au fost selectate mai multe informatii.Corectati selectia!", vbInformation, "Atentie"
End Sub
 
Upvote 0

Forum statistics

Threads
1,225,399
Messages
6,184,752
Members
453,254
Latest member
topeb

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