Hi I would like to parse the doc name to be opened and run some code before
document opening if when parsing the document name I found some particular
stuff..

Within the (document_open event)

if instr("key string",activedocument.name) >0 then
run some code
else
end if

I can't get it working , can someone give me some help ? Am I doing
something wrong ? How can I achieve that ?

Re: run some code before doc opening by Helmut

Helmut
Tue Apr 12 07:21:43 CDT 2005

Hi,

I think, you would have to adapt
fileopen to your needs.

If you check the name of the activedocument,
it might be too late already.


>Within the (document_open event)
>
>if instr("key string",activedocument.name) >0 then
>run some code
>else
>end if
>
>I can't get it working , can someone give me some help ?

Not working at all, or not working as you expected?

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000



RE: run some code before doc opening by mansky99

mansky99
Sat May 28 18:55:01 CDT 2005



"Herve cadieu" wrote:

> Hi I would like to parse the doc name to be opened and run some code before
> document opening if when parsing the document name I found some particular
> stuff..
>
> Within the (document_open event)
>
> if instr("key string",activedocument.name) >0 then
> run some code
> else
> end if
>
> I can't get it working , can someone give me some help ? Am I doing
> something wrong ? How can I achieve that ?

Don't know if you got an answer yet, I just ran across your post.

The simplest way is to create a module called "FileOpen" in your Normal
template as per the original answer suggested. In particular, I would
recommend using the "Display" method and not the "Show" method for the Dialog
FileOpen, so that your code can do some work before the file is actually
opended. The "Show" method will execute the Dialog window and not give you a
chance to get your own code to process anything before the file is actually
opened.

Here's a snippet of code as an example:

Sub FileOpen()
Dim FO As Dialog

Set FO = Dialogs(wdDialogFileOpen)
RetCode = FO.Display
If (RetCode = 0) Then
Exit Sub 'cancel button pressed, exit
End If

NewPathFileName = FO.Name

.... your processing code goes here ......


EndSub

The string NewPathFileName will be the full path and filename the User
inputs in the FileOpen dialog window.

Note you can then open the Document yourself via:

Documents.Open Filename:=Docname

where Docname is the filename part in NewPathFileName, which you'll have to
split apart yourself.


Hope this helps.


Ed