Good Morning. I am having trouble with a segment of code that has worked well in the past for me.
Private Sub Workbook_Open()
UserForm1.Show
End Sub
Stored in the UserForm
Private Sub CommandButton1_Click()
' Verify All Fields
Msg = "Have you entered all Fields?"
Title = "TONU"
Config = vbYesNo + vbQuestion
Ans = MsgBox(Msg, Config, Title)
If Ans = Yes Then GoTo nextstep:
If Ans = No Then Exit Sub
nextstep:
' Print Option
Msg1 = "Would you like to Print a hard copy?"
Title1 = "TONU"
Config1 = vbYesNo + vbQuestion
Ans1 = MsgBox(Msg1, Config1, Title1)
If Ans1 = Yes Then UserForm1.Print
If Ans1 = No Then Run Report
lastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row + 1
MsgBox lastRow
End Sub
The UserForm prints fine in my other project, but when a use this code in a new project it does not print?!?! Thoughts?
“Yes” is not a valid
VbMsgBoxResult. It should bevbYesorvbNo. In the first instance your code will just fall through toNextStep. In the second it will do nothing.To avoid this type of error use
Option Explicitat the top of your modules. Then it will complain that Yes and No are undeclared variables.Better yet, check “Require Variable Declaration” in Tools>Options, to have Option Explicit automatically placed at the top of each module.