run some code before doc opening

H

Herve cadieu

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 ?
 
H

Helmut Weber

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
 
M

mansky99

Herve cadieu said:
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
 

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