Slight Change To Code

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,822
Office Version
  1. 365
Platform
  1. Windows
I have this line of code that only makes changes to .xlsx files. How do I change it so it does .xlsm files also please?

Code:
strF = Dir(strP & "\*.xlsx")
 
No problem, glad to help.
For information, it will also include the XLSB files since "?" represents "any single character".
 
Upvote 0
For some reason it didn't work on all codes I have this in, may be other parts of code affecting it. Could something like below be done?

Code:
strF = Dir(strP & "\*.xlsx", "\*.xlsm")

All codes work ok when I change between .xlsm and .xlsx but not when there are a mixture of both in a folder.
 
Upvote 0
I do not think it is possible unfortunately. cf. Dir function (Visual Basic for Applications) | Microsoft Learn

I would do the check afterwards, but with all the code it would be easier to guide you because you probably need refactoring on your loop.
Something like
VBA Code:
Sub Example()
  Dim strP As String, strF As String
  strP = "C:\French\Recipes\Secrets\FrogSoup\Ingredients\"
  strF = Dir(strP)
  Do While strF <> VbNullString
    If LCase$(strF) Like "*.xls[xm]" Then
      ' do your things
    End If
    strF = Dir()
  Loop
End Sub
 
Upvote 0
I do not think it is possible unfortunately. cf. Dir function (Visual Basic for Applications) | Microsoft Learn

I would do the check afterwards, but with all the code it would be easier to guide you because you probably need refactoring on your loop.
Something like
VBA Code:
Sub Example()
  Dim strP As String, strF As String
  strP = "C:\French\Recipes\Secrets\FrogSoup\Ingredients\"
  strF = Dir(strP)
  Do While strF <> VbNullString
    If LCase$(strF) Like "*.xls[xm]" Then
      ' do your things
    End If
    strF = Dir()
  Loop
End Sub
Thanks. Some are very complex codes so I will just change to suit each time.
 
Upvote 0

Forum statistics

Threads
1,226,907
Messages
6,193,600
Members
453,810
Latest member
Gks77117

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