Stop a call list?

cns324

New Member
Joined
Jan 21, 2022
Messages
37
Office Version
  1. 365
Platform
  1. Windows
Hello, I have a list of macros I run with a call list, what I want to do is create a condition that stops the list if not met.
Here is the list:

Sub Button3_Click()
Application.ScreenUpdating = False
Call export
Call Step1
Call BlankDelete
Call FullDelete
Call IndDelete
Call ResDelete
Call PermanentDelete
Call Step2
Call email
Application.ScreenUpdating = True
End Sub

Current the export macro is this:
Sub export()
For Each wb In Application.Workbooks
If wb.Name Like "export*" Then
wb.Activate
Exit For
End If
Next wb
End Sub

I want to change it so that if it doesn't find the wb.name like "export*", then it gives an error message: "Export workbook not found" and it ends the call list of macros. Any help to achieve this is greatly appreciated!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try changing export() to a function that returns a boolean. True if "export*" is found. False if it is not. And then only execute the list if it was found.


VBA Code:
Sub Button3_Click()

    If export Then
        Application.ScreenUpdating = False
        Call Step1
        Call BlankDelete
        Call FullDelete
        Call IndDelete
        Call ResDelete
        Call PermanentDelete
        Call Step2
        Call Email
        Application.ScreenUpdating = True
    Else
        B = MsgBox("Export workbook not found")
    End If
End Sub

Function export() As Boolean
    export = False
    For Each wb In Application.Workbooks
        If wb.Name Like "export*" Then
            export = True
            wb.Activate
            Exit For
        End If
    Next wb
End Function
 
Upvote 0
Thanks for the help! I'm getting a compile error, for without next for the function.
 
Upvote 0
Never mind, I missed the next Next wb. Thanks testing now
 
Upvote 0
I was going to say that I am not getting that error. But for testing, I have 2 workbooks open, export1 and export2. The for loop you had in your code is only finding export2. So you might have to find another way to find all of the workbooks
 
Upvote 0
It's working, but it is giving me the message Export workbook not found, for each open workbook and when giving me that message after it finds the export wb and completes the list. Is there a way for to have it only give the message once? Thanks
 
Upvote 0
Maybe a global boolean like FoundAtLeastOne that gets set to true when find any. Then only do the msgbox if FoundAtLeastOne = False
 
Upvote 0

Forum statistics

Threads
1,214,981
Messages
6,122,565
Members
449,089
Latest member
Motoracer88

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