Error Resolution

tljenkin

Board Regular
Joined
Jun 14, 2007
Messages
147
Hi All,

I have the following code below. If the user says yes when in fact the file is not open, I want excel to prompt a message "Sorry appears file is not open, try again". Otherwise continue as normal.

Please help!

Sub UpdateDatabase()

Dim FileToBeOpened As Variant, File As Variant, Ard As Workbook, Wrr As Workbook
Set Ard = ThisWorkbook ' or Actuals repository current version presently open

Application.ScreenUpdating = False

Dim Response As Integer
Response = MsgBox(prompt:="Is the most recent weekly Redress report open?", Buttons:=vbYesNo)
If Response = vbYes Then


For Each Wrr In Application.Workbooks
If Wrr.Name Like "Week*" Then Wrr.Activate
Next Wrr
Set Wrr = ActiveWorkbook
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
I guess that didnt read very clear.

What I meant to say was this:

If you expect the user to answer yes if a file is already open or no if its not, if for example they answer yes its open when in fact its not, can excel end the sub with a message that "the file is not open"? How do I code this?

Many thanks
 
Upvote 0
But i am asking excel to look for a file with a wildcard, see code. Can i use the file exist code with a wild card?
 
Upvote 0
Try:

Code:
    Dim WB As Workbook
    Response = MsgBox(prompt:="Is the most recent weekly Redress report open?", Buttons:=vbYesNo)
    If Response = vbYes Then
        For Each Wrr In Application.Workbooks
            If Wrr.Name Like "Week*" Then
                Set WB = Wrr
                WB.Activate
                Exit For
            End If
        Next Wrr
    Else
        Exit Sub
    End If
    If WB Is Nothing Then
        MsgBox "The file is not open."
        Exit Sub
    End If
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

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