Hello,

Currently, I am working on a document that analyzes other documents.
Basically, the user clicks on a button and a dialog box opens up to
browse to a file and the analyzation begins.
It can bring up the dialog box correctly and minimize the current
window of the original document, but when I try to bring the document
to be analyzed into focus, it gives the error:

'Runtime error 5941':
The requested member of the collection does not exist.

Here is the code:
With Dialogs(wdDialogFileOpen)
.Display
DocToAnalyze = WordBasic.FilenameInfo$(.Name, 2)
End With
'On Error GoTo ErrorHandler

'Windows(analyzedoc).WindowState = wdWindowStateMinimize
Windows(DocToAnalyze).Activate

I have commented everything out around the last line and targeted it as
the source of the error, but I am not for sure why. I have tried
putting in other documents open such as "Document4.doc" and "Document4"
but to no avail.

Thank you for any help.

Re: Switching Windows Error by Doug

Doug
Thu May 25 09:53:32 CDT 2006

Use:

Dim mydoc as document
Dim DocToAnalyze as String

With Dialogs(wdDialogFileOpen)
.Display
DocToAnalyze = WordBasic.FilenameInfo$(.Name, 2)
End With
Set mydoc = Documents.Open(DocToAnalyze
mydoc.Activate


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"C_P" <Cameron.39@gmail.com> wrote in message
news:1148563631.481587.171950@i39g2000cwa.googlegroups.com...
> Hello,
>
> Currently, I am working on a document that analyzes other documents.
> Basically, the user clicks on a button and a dialog box opens up to
> browse to a file and the analyzation begins.
> It can bring up the dialog box correctly and minimize the current
> window of the original document, but when I try to bring the document
> to be analyzed into focus, it gives the error:
>
> 'Runtime error 5941':
> The requested member of the collection does not exist.
>
> Here is the code:
> With Dialogs(wdDialogFileOpen)
> .Display
> DocToAnalyze = WordBasic.FilenameInfo$(.Name, 2)
> End With
> 'On Error GoTo ErrorHandler
>
> 'Windows(analyzedoc).WindowState = wdWindowStateMinimize
> Windows(DocToAnalyze).Activate
>
> I have commented everything out around the last line and targeted it as
> the source of the error, but I am not for sure why. I have tried
> putting in other documents open such as "Document4.doc" and "Document4"
> but to no avail.
>
> Thank you for any help.
>



Re: Switching Windows Error by C_P

C_P
Thu May 25 15:02:56 CDT 2006

Doug,

Thanks for the tip. It is now working properly.