0

So what I have been doing is running my first set of code which will open new workbooks with specific data and then pasting different code into the new workbooks made and running it.

I was wondering if there is a way to use a message box in the first set of code to run the second set of code at the end?

MsgBox "Would you like to populate the team lists?", vbOKCancel
If Result = vbYes Then

Need to know what to put into the Then. I know I can just put the code in the Then but it's 2000 lines so I was hoping it could run somewhere else.

Robert Todar
  • 2,085
  • 2
  • 11
  • 31
Domo
  • 11
  • 1
  • Possible duplicate of [this](https://stackoverflow.com/questions/34211496/run-a-macro-from-another-workbook) SO question? – Jeroen Heier Aug 14 '19 at 17:25

1 Answers1

2

You can do this:

If MsgBox("Would you like to populate the team lists?", vbOKCancel) = vbOK Then
    'run your code
End If
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • see bottom of post – Domo Aug 14 '19 at 16:47
  • 2
    @Domo read up on the basics of how procedure scopes work in VBA. Your largest procedure should be something like 50 lines, tops. 2000 lines is well beyond what's acceptable. Put it in some `Private Sub DoSomething` procedure, and then make that msgbox conditional block call `DoSomething` where this very correct answer says "run your code". – Mathieu Guindon Aug 14 '19 at 17:03