File Object

Sigma248

Registered User.
Local time
Today, 14:32
Joined
Oct 6, 2008
Messages
24
I am trying to access an existing .jpg file with the following procedure:

Public Sub Check_For_Files(Filespec As String)
Dim fs, f, s

Dim Filespec_2 As String

Set fs = CreateObject("Scripting.FileSystemObject")

Filespec_2 = Filespec & ".jpg"

Set f = fs.GetFile(Filespec_2)

s = f.DateCreated

MsgBox s

End Sub


where Filespec = path to file & file name e.g. C:\Dean\Test_1010

I get a file not found error at the GetFile function.

Any suggestions?
 
I'm just guessing but you should put a message box just after you create Filespec_2 so you can see exactly what is in it. I'm guessing you are missing a backslash.
 
Problem Solved: I had the wrong folder path once again. I am going to have to be alot more careful with these.
 
Glad you're sorted - and yes, you need to always be mindful of the things as simple as making your folder path accurate even when trying something new that might be holding your concentration.
You can be knee deep in some relatively involved code and realise that a single character in a stored string of the wrong case is what's wasted a couple of hours of your time.
(Not that that's ever happened to me of course lol :-p)

Just to mention a point raised by Adam...
Variants are the whipping boy of VBA. You can literally shove *anything* into them.
They're a big vacuous 16 byte hole.
They've often used for unknown datatypes - or when a string might contain a Null - but they happily contain objects or whatever we see fit to deposit therein.
In the case of working with objects - such as the FSO here - then it's more common practice to use a dedicated "Object" variable type.
These are a mere 4 byte pointer to the object you're about to create, but would be used identically in this case.
e.g. you'll very often see
Dim f as Object
Set f = CreateObject("Scripting.FileSystemObject")
in late binding coding.
It's just better practice in general.

Cheers.
 

Users who are viewing this thread

Back
Top Bottom