# Excel VBA: Sub to find if URL exists



## tulip123 (Apr 17, 2001)

I need to find out whether a file which is actually a URL (i.e. it is located on a web-server) exists, from a VBA subroutine in Excel. 
Any way to do that ?


----------



## Anne Troy (Feb 14, 1999)

Your questions sound an awful lot like coursework. We don't want to answer your coursework questions for you. However, we hope you'll be honest about it and tell us if that's what you're doing. What we WILL do is give you a lot of guidance/direction in finding your answers.

Also, if you are doing VBA coursework, might I suggest you get thyself to the newsgroups? Let me know if you need help with those.

Here's some really terrific Excel resources:

http://www.cpearson.com/excel/topic.htm
http://www.erlandsendata.no/english/downloads/index.htm
http://www.turedata.se
http://www.ozgrid.com
http://msdn.microsoft.com/library/officedev/office97/web/fulltoc.htm

Good luck!


----------



## tulip123 (Apr 17, 2001)

Hi Dreamboat,

This is not a coursework question, it's a real problem I encountered while working on an Excel VBA application.

I'll manage it some other way.

Thanks,
Tulip.


----------



## nczman (Dec 12, 2000)

Those links gave me the answer to something I have been beating my head over for about a month now.

Kudos to Dreamboat......


----------



## Anne Troy (Feb 14, 1999)

Have you tried the newsgroups?

 *Hey, ncz.*
Very happy to hear it. Should'a just asked me.


----------



## nczman (Dec 12, 2000)

I thought about it, but that takes all of the fun out of getting frustrated....lol...


----------



## tulip123 (Apr 17, 2001)

No I didn't.

I found out that the Open method of a workbook in the following way:

On Error Resume Next
Set wb = Workbooks.Open(FileName:="xxx")

' Checking if the file exists.
If wb Is Nothing Then


Else

End If


----------



## tulip123 (Apr 17, 2001)

No I didn't.

I found out that I can use the 'Open' method of a workbook in the following way:

On Error Resume Next
Set wb = Workbooks.Open(FileName:="xxx")

' Checking if the file exists.
If wb Is Nothing Then

' The file does not exist.
...

Else

' The file exists.
...

End If

and that the file name can be a URL. Of course, in this way the file will be opened in another Excel workbook, so if it's not needed later it should be closed (the files I want to check are always text files, so opening them in an Excel workbook will cause no problems).

I'm attaching the code so that if anybody else encounters this problem maybe this can help him/her (instead of sending them to newsgroups...)


----------



## Anne Troy (Feb 14, 1999)

Thanks, tulip!


----------

