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

  • Thread starter Thread starter houweipeng
  • Start date Start date
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).
 
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.
 
Back
Top