Error Handling

vidyanand

New Member
Joined
Jul 19, 2014
Messages
32
Hello, I am running loop which check for specific files in specific folder. To find if any of the files missing, I created variable which stores the details of the missing file. To test my code I remove 2 files from set of 7 files I want to search through code. But variable which stored missing file details showed only one file name. So what changes I need to do in the following code.

Sub test()

wrkbk = Array("C:\Users\Vidyanand\Documents\Macro Prelive\Birla Sun Life 95.xlsm", _
"C:\Users\Vidyanand\Documents\Macro Prelive\Birla Sun Life Dynamic Bond.xlsm", _
"C:\Users\Vidyanand\Documents\Macro Prelive\Birla Sun Life Fornt Line Equity.xlsm", _
"C:\Users\Vidyanand\Documents\Macro Prelive\Birla Sun Life Medium Term.xlsm", _
"C:\Users\Vidyanand\Documents\Macro Prelive\Birla Sun Life MIP Wealth 25.xlsm", _
"C:\Users\Vidyanand\Documents\Macro Prelive\Birla Sun Life Pure Value.xlsm", _
"C:\Users\Vidyanand\Documents\Macro Prelive\Birla Sun Life Top 100.xlsm")

srch = Array("BIRLA SUN LIFE BALANCED 95 FUND", "BIRLA SUN LIFE DYNAMIC BOND FUND", _
"BIRLA SUN LIFE FRONTLINE EQUITY FUND", "BIRLA SUN LIFE MEDIUM TERM PLAN", _
"BIRLA SUN LIFE MIP WEALTH 25 PLAN", "BSL PURE VALUE FUND", _
"BIRLA SUN LIFE TOP 100 FUND")



For i = LBound(wrkbk) To UBound(wrkbk)


If Dir(wrkbk(i)) = "" Then

errm = srch(i) & " file not found" & vbNewLine
End If
Next


If errm <> "" Then
MsgBox errm
Else
MsgBox "All ok"
End If


End Sub
 

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.

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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