Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 16th, 2008, 08:12 PM
Authorized User
 
Join Date: Jul 2004
Location: New Providence, NJ, USA.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems referencing FileSystemObject

I need help w/ a problem I have encountered before....

I am writing an Excel application that will be distributed to non-programmer end-users. Within the project I need to check for the existence of some files on the user's machine. Needless to say, inside the VBA IDE I click on the Windows Script Host Object Model as a library reference, start using the FileSystemObject (yes, Dim fso as FileSystemObject, then Set fso = new CreateObject(blah-blah)) and write the code the find the appropriate file(s).

However, in doing this my experience has been that when the end-user runs the macro he is greeted with an error message about not himself having included the WSHOM as a library reference. I REALLY want to avoid this problem.

So, after some digging I am now playing with the following Declare statement and Sub:

    Public Declare Function FileExists Lib "scrrun.dll" ()

    Public Sub Test()
    dim pathFlNm
    pathFlNm = some legit path and file name string...

    If FileExists(pathFlNm) Then
        MsgBox "Found It!"
        Else
        MsgBox "No luck"
    End If
    End Sub

When I run this sub, however, I get an error message "Can't find DLL entry point FileExists in scrrun.dll"

So, two questions, I guess...

1) Am I even on-target with trying to use a Declare Statement as a way to avoid having my non-programmer end-users having to rummage around in the VBA IDE to get my macro(s) to run?

2) If so, how do I set up the Declare statement and subsequent Subs to work?
__________________
ArtDecade
Reply With Quote
  #2 (permalink)  
Old November 17th, 2008, 02:45 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Can you try the Dir function instead:

Code:
Public Sub Test()
    Dim pathFlNm

    pathFlNm = "c:\temp\sample.txt"

    If Len(Dir(pathFlNm)) <> 0 Then
        MsgBox "Found It!"
        Else
        MsgBox "No luck"
    End If
    End Sub
Cheers
Shasur

C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
  #3 (permalink)  
Old November 17th, 2008, 07:22 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Use HELP in Access. (Because the HELP in Excel is woefully inadequate! But the fundamentals of VBA are the same in all the Office products.)

Click on "Table of Contents".
Click on "Microsoft Visual Basic Documentation"
Click on "Visual Basic Language Reference"
Click on "Statements"
Click on "A-L"
Click on "Declare Statement"
Read.

Read especially the "Remarks". Including this:
Quote:
quote:
Remarks
...
Empty parentheses indicate that the Sub or Function procedure has no arguments and that Visual Basic should ensure that none are passed.
...
So NOW try using
Code:
Public Declare Function FileExists Lib "scrrun.dll" (path As String) As Boolean
And see if it works.

[Untested by me! Just reading the docs, period!]
Reply With Quote
  #4 (permalink)  
Old November 17th, 2008, 08:00 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

The reason I think this might be the problem is the message you go:
     Can't find DLL entry point FileExists in scrrun.dll

Excel was clearly able to find "scrrun.dll" and clearly able to scan it for entry points.

So I *think* the problem is that it is looking for a function named FileExists that takes no arguments, as you specified (inadvertently).

It's been years since I worked with VB and used the DECLARE statement in it, but I vaguely recalled the need to match arguments, so...

Hope this works!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help about FileSystemObject vbpratap VB.NET 0 March 3rd, 2006 06:40 AM
Using the FileSystemObject malhyp Dreamweaver (all versions) 1 October 2nd, 2005 07:00 AM
Chap 10 FileSystemObject Problems orbbital BOOK: Beginning ASP 3.0 2 April 20th, 2005 10:19 AM
I need help with FileSystemObject ... PLEASE xanderxvr Classic ASP Professional 0 January 31st, 2005 02:56 AM



All times are GMT -4. The time now is 09:13 AM.


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