Bookmarks and modal dialogs

D

DeborahK

Here is my problem:
1) I am adding a menu to Word that displays a VB.NET Windows Form.
2) In the code for that windows form, I am creating new Word documents.
3) I am setting a bookmark in one of the new documents so the user is
returned to that document when processing is complete.

Step #3 does NOT work when I make the VB.NET Windows Form a modal dialog. It
does work correctly when the form is modeless.

Any idea why?

Any idea how to get it to work with a modal dialog? (The client wants these
dialogs to be modal.)
 
J

Jean-Guy Marcil

DeborahK was telling us:
DeborahK nous racontait que :
Here is my problem:
1) I am adding a menu to Word that displays a VB.NET Windows Form.
2) In the code for that windows form, I am creating new Word
documents. 3) I am setting a bookmark in one of the new documents so
the user is returned to that document when processing is complete.

Step #3 does NOT work when I make the VB.NET Windows Form a modal
dialog. It does work correctly when the form is modeless.

Any idea why?

Any idea how to get it to work with a modal dialog? (The client wants
these dialogs to be modal.)

No, no idea... you have to show us your code so that we can have an idea...

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
D

DeborahK

Well, here is the code that returns to the bookmark:

''' <summary>
''' Returns to a bookmark in the defined document
''' </summary>
''' <param name="sOriginalDocumentName">Name of the document to return
to</param>
Public Shared Sub ReturnToBookmark(ByVal sOriginalDocumentName As String)
With WordInstance
If sOriginalDocumentName.Length > 0 Then
For Each oDoc As Word.Document In .Documents
If oDoc.Name = sOriginalDocumentName Then
oDoc.Activate()
Exit For
End If
Next

' Then move to the bookmark
If .ActiveDocument.Bookmarks.Count > 0 Then
With .ActiveDocument.Bookmarks.Item("ReturnToHere")
.Select()
'.Delete()
End With
End If
End If
End With
End Sub
 
J

Jean-Guy Marcil

DeborahK was telling us:
DeborahK nous racontait que :
Well, here is the code that returns to the bookmark:

''' <summary>
''' Returns to a bookmark in the defined document
''' </summary>
''' <param name="sOriginalDocumentName">Name of the document to
return to</param>
Public Shared Sub ReturnToBookmark(ByVal sOriginalDocumentName As
String) With WordInstance
If sOriginalDocumentName.Length > 0 Then
For Each oDoc As Word.Document In .Documents
If oDoc.Name = sOriginalDocumentName Then
oDoc.Activate()
Exit For
End If
Next

' Then move to the bookmark
If .ActiveDocument.Bookmarks.Count > 0 Then
With .ActiveDocument.Bookmarks.Item("ReturnToHere")
.Select()
'.Delete()
End With
End If
End If
End With
End Sub

Not sure about this, (this is a vba group, nit a VB.NET!), but here goes:

Is is necessary to Activate the document?

Try this:

If .ActiveDocument.Bookmarks.Count > 0 Then
.ActiveDocument.Bookmarks.("ReturnToHere").Range.Select()
End If

Try with and without the Activate part that precedes.

Also, using Select and Activate with a modal form that is being displayed
may not be a good idea.
Try placing the "ReturnToBookmark" Sub in a standard module and call it
after closing the modal form.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
D

DeborahK

Thanks for giving this a try.

The problem definitely is that any bookmark selection and activiation is
ignored when there is a modal dialog up.

I had to re-architect it such that all of the dialogs had a property
defining the name of the document to activate. After closing and terminating
the modal dialog, I could then active the document and move to the bookmark.

FWIW - I could not find an Office newgroup for .NET that was not MSTO -
which we cannot use because we have to support down to Word 2000. Do you know
of one?

Thanks again for taking a look!
 
J

Jean-Guy Marcil

DeborahK was telling us:
DeborahK nous racontait que :
Thanks for giving this a try.

The problem definitely is that any bookmark selection and activiation
is ignored when there is a modal dialog up.

I had to re-architect it such that all of the dialogs had a property
defining the name of the document to activate. After closing and
terminating the modal dialog, I could then active the document and
move to the bookmark.

FWIW - I could not find an Office newgroup for .NET that was not MSTO
- which we cannot use because we have to support down to Word 2000.
Do you know of one?

Sorry, not really. There are VB.Net groups, but they might not know about
the Word object model.

You may have to decide if the problem is a language problem, then post to
VB.NET, or a Word problem, then post here, knowing that you may not get help
directly with the coding itself, but more on the concepts.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top