Do While file is Workbook ( open only XL files in folder )

Akbarov

Active Member
Joined
Jun 30, 2018
Messages
347
Office Version
  1. 365
Platform
  1. Windows
Hello community,

I am trying to use following VBA , to open each file in folder ( but in folder there are different kind of files too like .pptx etc. ) I want to use it to open only Excel Workbooks

VBA Code:
Do While MyFile <> "" And MyFile Is Workbook
   'Opens the file and assigns to the wbk variable for future use
   Set wbk = Workbooks.Open(Filename:=MyFolder & MyFile)
   wbk.Activate

Can anyone tell me what I do wrong?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
What I do wrong? it stops when faces different kind of file.
Instead I want it to loop next file
VBA Code:
Do While MyFile <> ""
If Right(MyFile, 3) = "xls" Or Right(MyFile, 4) = "xlsm" Then
   Set wbk = Workbooks.Open(Filename:=MyFolder & MyFile)
Else
End If
 
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,738
Members
449,094
Latest member
dsharae57

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