Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Dir Function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Warrio - 20 Jul 2007 17:54 GMT
Hello

I am using the Dir function to see if the path that I have is still valid.

It works perfectly if the path begins with a drive, but when I try with a
file stored on a server or on internet, it can't work and shows the error
message "Bad file name or number".

if Dir("http://www.microsoft.com/myDoc.doc")  = "" then    MsgBox "File not
found!"

Is there something that I forgot or is there another way to make this check?

Thanks for any suggestion!
Best regards.
old man - 20 Jul 2007 19:10 GMT
Hi,

You can try mapping the network drive to a letter and then use dir against
the mapped drive. MS has s support note for using dir on a UNC  file without
an extension (which a folder typically is) and MS suggest using the openfile
API to do so - the support note has a good example how to do so:

http://support.microsoft.com/kb/168519

You can also use an object called fso to check if a UNC folder exists. Karl
Peterson recently noted some of the issues involved in using FSO in VBA in
this forum but if used carefully can be a direct (non-api) solution to your
problem.

old man

old man

> Hello
>
[quoted text clipped - 11 lines]
> Thanks for any suggestion!
> Best regards.
Karl E. Peterson - 24 Jul 2007 19:49 GMT
OP was asking about an HTTP location.  I don't believe FSO works any differently
than any other file/folder-based solution for this sort of test, does it?
Signature

.NET: It's About Trust!
http://vfred.mvps.org

> Hi,
>
[quoted text clipped - 29 lines]
>> Thanks for any suggestion!
>> Best regards.
Jonathan West - 20 Jul 2007 19:14 GMT
> Hello
>
[quoted text clipped - 12 lines]
> Thanks for any suggestion!
> Best regards.

Try this instead

http://vbnet.mvps.org/index.html?code/fileapi/fileexists.htm

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Warrio - 23 Jul 2007 17:22 GMT
Hi Jonathan,
Thanks for your answer!

I tried the function you advised me, but unfortunately it doesn't work...
When I try it with an intranet file beginning with an "http://", it return
FALSE.
but when I try to open it "manually" with Word, the file is successfully
opened after a small window saying "Conneting to web server ..."

maybe this window is taken as an error by the function FindFirstFile...

Thanks again

>> Hello
>>
[quoted text clipped - 17 lines]
>
> http://vbnet.mvps.org/index.html?code/fileapi/fileexists.htm
Russ - 23 Jul 2007 19:11 GMT
Intranet ( within one network ) file usually begins with file://
Internet ( between networks ) file usually begins with http://

Can you prefix the url with file:// and try it?
> Hi Jonathan,
> Thanks for your answer!
[quoted text clipped - 30 lines]
>>
>> http://vbnet.mvps.org/index.html?code/fileapi/fileexists.htm

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Warrio - 23 Jul 2007 19:30 GMT
I don't have access because of the company's policies... with file://

(and it's an intranet (LAN) even if it starts with http:// you can have
hyperlinks even on not connected computer...)

but file doen't solve my problem..
Thanks anyway!

> Intranet ( within one network ) file usually begins with file://
> Internet ( between networks ) file usually begins with http://
[quoted text clipped - 37 lines]
>>>
>>> http://vbnet.mvps.org/index.html?code/fileapi/fileexists.htm
Jonathan West - 23 Jul 2007 22:34 GMT
> Hi Jonathan,
> Thanks for your answer!
>
> I tried the function you advised me, but unfortunately it doesn't work...
> When I try it with an intranet file beginning with an "http://", it return
> FALSE.

It would. It is inly intended to work with files on a local drive, a mapped
network drive or with a UNC path.

> but when I try to open it "manually" with Word, the file is successfully
> opened after a small window saying "Conneting to web server ..."

That is because the file is being downloaded into your temp folder and then
opened by Word. Witrh that downloaded file open, go to the immediate window
in the VBA editor and type the following

? ActiveDocument.Fullname

You will find the location of the doc on your local drive.

If you want to find whether an http url exists, then you need a different
approach, possibly using the Windows API function InternetConnect. I'm not
an expert in this area but if you do a search for that function you will
probably find something.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Warrio - 24 Jul 2007 11:02 GMT
Thanks a lot for your help!

>> Hi Jonathan,
>> Thanks for your answer!
[quoted text clipped - 21 lines]
> an expert in this area but if you do a search for that function you will
> probably find something.
old man - 20 Jul 2007 19:30 GMT
Hi,

By the way you want to use a UNC type notation which typically looks like
this:
\\server\dir\dir\file....

I would first try J. West's solution....

Old Man

> Hello
>
[quoted text clipped - 11 lines]
> Thanks for any suggestion!
> Best regards.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.