How to skip the current file when using strFile = Dir(strPath & "*.xlsm")

kpierce

Board Regular
Joined
Jun 21, 2010
Messages
76
I have received a lot of help on this form and I thank you.

I want to read through all the *.XLS* files in a given directory.

I would like to put the XLS* file with the macros in the same directory, but don't want to read that file.

Currently I have this working by having the master XLS* in a different directory. And I am now to the point I would like to put everything in one directory.

* I have the following line working
strFile = Dir(strPath & "*.xlsx")

*I would like to do something like.
If strFile = Me or Execute File...

I could easily require the master file always have the same name, but don't know if that would work.

In summary

in the same directory
MASTER.XLSM
FILE1.XLSM
FILE2.XLSM
FILE3.XLSM

I will open MASTER.XLSM and execute a macro to read all the XLSM files in the current directory, but I don't want to skip MASTER.XLSM.

Thanks <!-- / message --><!-- BEGIN TEMPLATE: ad_showthread_firstpost_sig --><!-- END TEMPLATE: ad_showthread_firstpost_sig -->
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I will open MASTER.XLSM and execute a macro to read all the XLSM files in the current directory, but I don't want to skip MASTER.XLSM.

Thanks <!-- / message --><!-- BEGIN TEMPLATE: ad_showthread_firstpost_sig --><!-- END TEMPLATE: ad_showthread_firstpost_sig -->
I assume that's a typo.

Your workbook is called ThisWorkbook.Name, so your code would be:-
Code:
[FONT=Fixedsys]If strFile<>ThisWorkbook.Name Then[/FONT]
[FONT=Fixedsys][COLOR=green]   ' file isn't me - process this file[/COLOR][/FONT]
[FONT=Fixedsys]End If[/FONT]

Also, your path is ThisWorkbook.Path.
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

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