Check folder for file exists, if - run set of subs, else - run different set of subs

kstate1988

New Member
Joined
Jun 7, 2016
Messages
9
I have a report that i want to run based on a files existence in a folder on my desk top.

My desired result:

Click on the "ActiveX Box",

Macro would run to determine if file "Dealer Inventory" exist.

If, it exist

Then, run Private Sub RunPLTS()

Else, run Private Sub RunNOPLTS()

End

Would appreciate any help provided!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Code:
  Dim sFile As String
  
  sFile = "C:\somePath\someFile"
  If Len(Dir(sFile)) Then RunPLTS Else RunNOPLTS
 
Upvote 0
shg,

Tried code and cannot get it to work.

This is the path I have to use to get to the "Inventory" file.

(Environ("USERPROFILE") & "\Desktop\GM Inventory Report\Inventory")

It keeps kicking an error.

Also, when the code does not error it directs me to the Macros box to choose which macro I wish to run, not automatic?

Thank for the help.
 
Last edited:
Upvote 0
"Inventory" is an odd filename; it has no extension.
 
Upvote 0
It pulls the file and puts it into a workbook with no issues?

C:\Users\R000180\Desktop\GM Inventory Report

This is the path I get when I right click on file name.

R000180 = Is my employee number for this computer.
 
Upvote 0
You probably have Windows configured to suppress extensions for known filetypes. Add the extension in the code.
 
Last edited:
Upvote 0
Thank You all for the responses.

I finally figured it out and this is what I came up with.

Had to have modify my file path due to a corporate computer.

Sub Checkfile()


Dim FilePath As String
FilePath = (Environ("USERPROFILE") & "\Desktop\GM Inventory Report\Inventory.csv")
If Dir(FilePath) <> "" Then
Application.Run "RunPLTS_Click"
Else
Application.Run "RunNOPLTS_Click"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,983
Messages
6,175,779
Members
452,668
Latest member
mrider123

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