Search for file in directory

j844929

Active Member
Joined
Aug 18, 2002
Messages
423
Hi,

I have some code that creates a versioned file name from data in an info form in a workbook and saves the file as that name.

I have referred to the filename as BookName in the code.

What I'm having a problem with is creating the code that searches the directory to see if the filename exists already. If it doesn't exist, then I'll run the code to save the workbook as the current version. If it does already exist, then the code should increment the version number and then save it. The kind of thing I have so far is:

If Dir("C:/ "BookName" ") <> "" Then
Call IncrementVersion
Else
Call SaveIt
End If

Instead of looking for a specified filename each time, I need it to look for what "BookName" is. Does anyone have an idea on how to do this?

Any help would be appreciated.

Tim
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I've actually found the solution - it was incredibly easy.

All I did was to change the text in the search slightly...

If Dir("C:/" & Bookname & " ") <> "" Then
Call IncrementVersion
Else
Call SaveIt
End If

There you go - just a matter of a couple of ampersands!
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,684
Members
449,048
Latest member
81jamesacct

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top