K
KG
the following code was adapted from J. Walkenbach's book:
Private Sub CancelButton_Click()
Dim Msg As String
Dim Ans As Integer
Msg = "Cancel the wizard?"
Ans = MsgBox(Msg, vbQuestion + vbYesNo, APPNAME)
If Ans = vbYes Then Unload Me
End Sub
Public Sub UserForm1_Initialize()
MultiPage1.Value = 0
UpdateControls
With ActiveWorkbook
Me.TextBox1.Value = .Worksheets("sheet1").Range
("b3").Value
Me.TextBox2.Value = .Worksheets("sheet2").Range
("a9").Value
Me.TextBox3.Value = .Worksheets("sheet3").Range
("a9").Value
End With
End Sub
Sub UpdateControls()
Select Case MultiPage1.Value
Case 0
BackButton.Enabled = False
NextButton.Enabled = True
Case MultiPage1.Pages.Count - 1
BackButton.Enabled = True
NextButton.Enabled = False
Case Else
BackButton.Enabled = True
NextButton.Enabled = True
End Select
End Sub
Private Sub BackButton_Click()
MultiPage1.Value = MultiPage1.Value - 1
UpdateControls
End Sub
Private Sub NextButton_Click()
MultiPage1.Value = MultiPage1.Value + 1
UpdateControls
End Sub
Private Sub FinishButton_Click()
With ActiveWorkbook
.Worksheets("sheet1").Range("b3").Value =
Me.TextBox1.Value
.Worksheets("sheet2").Range("a9").Value =
Me.TextBox2.Value
.Worksheets("sheet3").Range("a9").Value =
Me.TextBox3.Value
End With
Unload Me
End Sub
The data are inserted correctly in the target cells in
this 3-worksheet workbook but there are a couple of
problems with this code:
1) The "Next" button fails to dim when the user reaches
the 3rd (and last) tab
2) I wanted the last entered data to remain in view when
the "wizard" is reactivated, so that the user does not
necessarily have to change the data in all three pages.
Right now, each time the wizard is reactivated, all three
sheets are set to null
Any help with this will be appreciated. MY VBA skills are
just not good to enough to solve this on my own
Private Sub CancelButton_Click()
Dim Msg As String
Dim Ans As Integer
Msg = "Cancel the wizard?"
Ans = MsgBox(Msg, vbQuestion + vbYesNo, APPNAME)
If Ans = vbYes Then Unload Me
End Sub
Public Sub UserForm1_Initialize()
MultiPage1.Value = 0
UpdateControls
With ActiveWorkbook
Me.TextBox1.Value = .Worksheets("sheet1").Range
("b3").Value
Me.TextBox2.Value = .Worksheets("sheet2").Range
("a9").Value
Me.TextBox3.Value = .Worksheets("sheet3").Range
("a9").Value
End With
End Sub
Sub UpdateControls()
Select Case MultiPage1.Value
Case 0
BackButton.Enabled = False
NextButton.Enabled = True
Case MultiPage1.Pages.Count - 1
BackButton.Enabled = True
NextButton.Enabled = False
Case Else
BackButton.Enabled = True
NextButton.Enabled = True
End Select
End Sub
Private Sub BackButton_Click()
MultiPage1.Value = MultiPage1.Value - 1
UpdateControls
End Sub
Private Sub NextButton_Click()
MultiPage1.Value = MultiPage1.Value + 1
UpdateControls
End Sub
Private Sub FinishButton_Click()
With ActiveWorkbook
.Worksheets("sheet1").Range("b3").Value =
Me.TextBox1.Value
.Worksheets("sheet2").Range("a9").Value =
Me.TextBox2.Value
.Worksheets("sheet3").Range("a9").Value =
Me.TextBox3.Value
End With
Unload Me
End Sub
The data are inserted correctly in the target cells in
this 3-worksheet workbook but there are a couple of
problems with this code:
1) The "Next" button fails to dim when the user reaches
the 3rd (and last) tab
2) I wanted the last entered data to remain in view when
the "wizard" is reactivated, so that the user does not
necessarily have to change the data in all three pages.
Right now, each time the wizard is reactivated, all three
sheets are set to null
Any help with this will be appreciated. MY VBA skills are
just not good to enough to solve this on my own