Selection.Goto behavior

Is there a way of knowing when the following code fails?

Selection.GoTo what:=wdGoToGraphic, Which:=wdGoToNext, count:=1, Name:=""

ie when there is no "next graphic".  Currently it just does nothing and continues, which is not good.

Ideally I'd like the same behavior as Selection.Find.Execute, which returns false if the find fails, but the API definition for Selection.GoTo does not mention any return value.
Answer
Answer

You could use something like:


Dim rng As range
Set rng = Selection.range
Selection.GoTo what:=wdGoToGraphic, which:=wdGoToNext
If Selection.range.Start = rng.Start Then
    MsgBox "There was no graphic to go to."

    Exit Sub

Else

    'Do whatever it is that you want done.
End If


However, I would try and avoid using the Selection object.


Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated April 14, 2025 Views 218 Applies to: