Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

vba error: object variable or with block variable not set

I have no idea what has just happened! Please help. Here is my code!

  If intMsgBox = vbYes Then
Unload frmNewOrder // error here
Unload Main_Menu //error here
ActiveSheet.PrintPreview
wkbNewOrder.Worksheets("New Order").Select
wkbNewOrder.Worksheets("New Order").Delete
wkbNewOrder.Worksheets("Main Menu").Select
End If
share|improve this question
1  
what are frmNewOrder and Main_Menu ? –  sam092 Oct 25 '13 at 5:32
1  
How do you get two errors? Doesn't the code stop after the first one? –  Jean-François Corbett Oct 25 '13 at 6:36
    
+ 1 LOL@Jean-FrançoisCorbett: That was also the first thing that came to my mind... :) –  Siddharth Rout Oct 25 '13 at 8:38

2 Answers 2

As explained in the documentation, neither Main_Menu nor frmNewOrder were set.

Screenshot of the link. In case the above link dies.

enter image description here

share|improve this answer
    
+ 1 That sums it all :) –  Siddharth Rout Oct 25 '13 at 8:36

It looks like you declared frmNewOrder as a variable but you did not set it and your code looks like this:

Dim MyForm As UserForm1
Unload MyForm

But it should be instead:

Dim MyForm As UserForm
Set MyForm = UserForm1
Unload MyForm
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.