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