Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 11th, 2007, 04:07 AM
Registered User
 
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Fileexists function

Hi,

I can't get this piece of code to work using the sub(filexists) funtion taken from the Excel VBA 2002 book. No matter whether the file exists or not the code always executes the else statement rather than the next statement. Every other part of the code works fine.

Any help greatly appreciated as it's been driving me mad for ages. I'm sure it's something simple.

Thanks
Dave

checkiffileisopen:
stfullname = pathname & "\" & stFileName & ".xls"
stFileName = GetFileName(stfullname)
If IsWorkbookOpen(stFileName) Then
Set Wkb = Workbooks(stFileName)
Wkb.Activate
Else
ChDir pathname
If FileExists(stFileName) = True Then
Set Wkb = Workbooks.Open(Filename:=stfullname)
Else
GoTo dontprocess:

End If

End If

 
Old January 11th, 2007, 04:24 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

You can also use the simple Dir function

fFile = Dir$(stfullname, vbNormal)
IF len(fFile) <> 0

 ' open the file

Else

 ' file does not exist

End if

Cheers
Shasur



http://www.vbadud.blogspot.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
function keyvanjan ASP.NET 2.0 Professional 1 September 19th, 2007 10:22 AM
send variable in function to another function schoolBoy Javascript How-To 6 March 3rd, 2007 09:16 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
need help for function mohiddin52 Access 2 June 8th, 2005 01:47 PM
retreive function/Line from macro or function? MikoMax J2EE 0 April 1st, 2004 04:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.