Running a macro but no file to open?

Carly

Active Member
Joined
Aug 21, 2002
Messages
370
We run a report each month which consists of opening a file for a rep area, manipulating the data, saving, then opening the next rep area and doing the same thing.

The problem we have is that there is not always data for every rep area, but we do not know which ones as they may be different each month.

We run the macro by having one module which runs each of the macros in turn:

i.e
Sub Run

Application.Run "reparea1"
Application.Run "reparea2"

End Sub

How do I write into the macro, if there isn't a file for reparea1 to open, stop the macro and continue with reparea2 module.

Please help

Carly
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi Carly,

Two possibilities occur to me:

1. Incorporate a "On Error Resume Next" statement. (However, you will then not be aware of any other errors that may arise. Depends what else is in your macro.)

2. Include a call to a subroutine that checks whether the workbook exists. Here is an example taken from Dave Hawley's site:

<pre>Sub DoesWorkBookExist()
'''''''''''''''''''''''''''''''
'Written by http://www.Ozgrid.com

'Test to see if a Workbook exists
''''''''''''''''''''''''''''''''
Dim i As Integer

With Application.FileSearch
.LookIn = "C:MyDocuments"
'* represents wildcard characters
.FileName = "Book*.xls"
If .Execute > 0 Then 'Workbook exists
MsgBox "There is a Workbook."
Else 'There is NOt a Workbook
MsgBox "The Workbook does not exist"
End If
End With
End Sub</pre>

HTH
 
Upvote 0

Forum statistics

Threads
1,203,453
Messages
6,055,530
Members
444,794
Latest member
HSAL

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