PDA

View Full Version : Dir in Word2011



Pathagoras
09-04-2011, 12:11 PM
In Word ((Windows), when I want to check for the presence of a file in a foler, I use:

IsThere=Dir("C:\folder\filename.doc")

If IsThere returns "" then the document is not there. If it returns "filename.doc", it's there.

I cannot seem to duplicate this in Word2011 (Mac)? That same command returns "Error 68, Device not available" and makes me click a button to exit the error screen when the document does not exist.

What am I doing wrong? There must be a way!

macropod
09-09-2011, 05:23 AM
Two things to check:
1. The Dir function exists in Mac Word vba
2. You're using the correct filepath names and separators for the Mac environment.

Frosty
09-09-2011, 03:50 PM
Application.PathSeparator may be useful in this context.

Pathagoras
09-12-2011, 06:38 AM
I am using the correct name and correct path separators. If the file exists, it returns the name of the file. If it does not exist, it returns an error.

My fix:
A new function:

[code]
Function ChkDir (file name)
On Error GoTo errorhandler
ChkDir=Dir(filename)
exit function
errorhandler"
ChkDir=""
Exit Function
[\Code]


It runs the actual Dir command. If it finds the file, it returns the name of the file. If it errors out, I have an errorhandler which sets ChkDir to "".

I replaced every instance of Dir in the other sections of my routine. Works great.

This is the same thing that Dir is supposed to do in the first place.