How can I get the valid full name, before I call .Documents.Open() method

H

houweipeng

Before I call Documents.Open() method, I want to know if the doc's full name
is invalid in any OS(eg, English os, JPN, CN).
 
J

Jay Freedman

houweipeng said:
Before I call Documents.Open() method, I want to know if the doc's
full name is invalid in any OS(eg, English os, JPN, CN).

Don't bother with writing a parser for file names -- that already exists in
Windows. Just include an On Error statement that will redirect the macro's
execution to an error handler if the name is invalid.

Dim MyFileName As String
MyFileName = "X:\bad path\possibly invalid filename.doc"

On Error GoTo BadFileName
Documents.Open(MyFileName)
' rest of the macro...

Exit Sub

BadFileName:
MsgBox MyFileName & " is not valid"


--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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