Wanting2Excel
New Member
- Joined
- Nov 27, 2012
- Messages
- 12
Hi again guys.
Ok so my problem is pretty much what it says in thread title. I have a workbook (WB1) that needs to be read only. Its going to be used by lots of people so don't want them messing things up. But some of the sheets in WB1, users will enter data on via a userform - So on WB1 I have a button with a link to the data sheet which is not read only (WB2). I have created the Userform and the code to populate the data onto WB2, it then saves and closes the sheet (WB2). But I want it to then take them back to WB1 - So that it seemlesly seems to anyone else that they never left the read only sheet to begin with....Does that make sense?
Here is the code I have so far:
What (if anything) can I do to make WB1 open after clicking submit on the userform to save and close WB2?
Ok so my problem is pretty much what it says in thread title. I have a workbook (WB1) that needs to be read only. Its going to be used by lots of people so don't want them messing things up. But some of the sheets in WB1, users will enter data on via a userform - So on WB1 I have a button with a link to the data sheet which is not read only (WB2). I have created the Userform and the code to populate the data onto WB2, it then saves and closes the sheet (WB2). But I want it to then take them back to WB1 - So that it seemlesly seems to anyone else that they never left the read only sheet to begin with....Does that make sense?
Here is the code I have so far:
Code:
Private Sub cmdSubmit_Click()
Dim RowCount As Long
If Me.txtDate.Value = "" Then
MsgBox "Please enter the date.", vbExclamation, "All fields need to be completed."
Me.txtDate.SetFocus
Exit Sub
If Not IsNumeric(Me.txtDate.Value) Then
MsgBox "The Amount box must contain a number.", vbExclamation, "Please enter date in dd/mm/yyyy format."
Me.txtDate.SetFocus
Exit Sub
End If
MsgBox "The Date box must contain a date.", vbExclamation, "Staff Expenses"
Me.txtDate.SetFocus
Exit Sub
End If
If Me.txtName.Value = "" Then
MsgBox "Please enter your name.", vbExclamation, "All fields need to be completed"
Me.txtName.SetFocus
Exit Sub
End If
If Me.txtQuestion.Value = "" Then
MsgBox "Please enter your question.", vbExclamation, "All fields need to be completed"
Me.txtQuestion.SetFocus
Exit Sub
End If
' Write data to Worksheet
RowCount = Worksheets("Sheet1").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet1").Range("A1")
.Offset(RowCount, 0).Value = Me.txtDate.Value
.Offset(RowCount, 1).Value = Me.txtName.Value
.Offset(RowCount, 2).Value = Me.txtQuestion.Value
ActiveWorkbook.Save
ActiveWorkbook.Close
Exit Sub
End With
End Sub
What (if anything) can I do to make WB1 open after clicking submit on the userform to save and close WB2?