avkokin
Tue Jul 15 23:13:06 PDT 2008
On Jul 15, 9:24=A0pm, avkokin <avko...@gmail.com> wrote:
> On Jul 15, 6:56=A0pm, "Jay Freedman" <jay.freed...@verizon.net> wrote:
>
>
>
>
>
> > Quoting the VBA Help topic for the InputBox function, 'If the user clic=
ks
> > Cancel, the function returns a zero-length string ("").' There is no
> > separate indication that the user clicked the Cancel button instead of
> > clicking Enter when the text box is empty -- as far as the macro is
> > concerned, those two actions are exactly the same. This is unfortunate,=
but
> > it has always been that way.
>
> > You have two alternatives. One is to accept the behavior of the InputBo=
x
> > function; remove the Do While loop and assume that a returned value of =
an
> > empty string just means "cancel the whole macro" (use an Exit Sub comma=
nd or
> > GoTo a label at the end of the procedure).
>
> > The other alternative is to replace the InputBox with a UserForm that y=
ou
> > create, containing a text box, a label, and OK and Cancel buttons. Then=
you
> > can define a variable in the General Declarations part of the UserForm'=
s
> > code to indicate whether the Cancel button was clicked. The calling mac=
ro
> > can check that variable's value before proceeding to use the string fro=
m the
> > text box.
>
> > --
> > Regards,
> > Jay Freedman
> > Microsoft Word MVP =A0 =A0 =A0 =A0FAQ:
http://word.mvps.org
> > Email cannot be acknowledged; please post all follow-ups to the newsgro=
up so
> > all may benefit.
>
> > avkokin wrote:
> > > Hello.
> > > How to handle of pressing button "Cancel" from dialogue InputBox? In
> > > my code when user press button "Cancel" dispaly Msgbox from cycle Do
> > > While. I need to cancel all action. See my code:
> > > Sub movePic()
> > > Dim Message As String
> > > On Error Resume Next
> > > If Selection.Type =3D wdSelectionInlineShape Then
> > > =A0 Selection.InlineShapes(1).ConvertToShape
> > > End If
> > > If Selection.Type =3D wdSelectionIP Then
> > > =A0 MsgBox "Please select your image"
> > > Else
> > > =A0 Do While Message =3D ""
> > > =A0 =A0 =A0Message =3D InputBox("Please enter the number." & _
> > > =A0 =A0 =A0vbCr & "...", _
> > > =A0 =A0 =A0"Move image", "")
> > > =A0 =A0 =A0 =A0 If Message =3D "" Then
> > > =A0 =A0 =A0 =A0 =A0 =A0MsgBox "Please enter the number"
> > > =A0 =A0 =A0 =A0 End If
> > > =A0 Loop
> > > =A0 Selection.ShapeRange.IncrementLeft MillimetersToPoints(Message)
> > > End If
> > > End Sub
>
> > > Thank you very much!- Hide quoted text -
>
> > - Show quoted text -
>
> Hello.
> I doing that:
> Sub movePic()
> Dim Message As String
> On Error Resume Next
> If Selection.Type =3D wdSelectionIP Then
> =A0 =A0MsgBox "Please select your image"
> Else
> =A0 =A0Do While Message =3D ""
> =A0 =A0 =A0 Message =3D InputBox("Please enter the number." & vbCr & "...=
",
> "Move image", "")
> =A0 =A0 =A0 If Message =3D vbNullString Then Exit Sub
> =A0 =A0 =A0 If Message =3D "" Then
> =A0 =A0 =A0 =A0 =A0MsgBox "Please select your image"
> =A0 =A0 =A0 End If
> =A0 =A0Loop
> =A0 =A0If Selection.Type =3D wdSelectionInlineShape Then
> =A0 =A0 =A0 Selection.InlineShapes(1).ConvertToShape
> =A0 =A0End If
> =A0 =A0Selection.ShapeRange.IncrementLeft MillimetersToPoints(Message)
> End If
> End Sub
>
> Thank you.- Hide quoted text -
>
> - Show quoted text -
I found that next code in my macro is superfluous:
If Message =3D "" Then
MsgBox "Please select your image"
End If