我在特定的WorkBook上有一個用戶表單,它所做的是從用戶那裏收集數據並將其轉儲到同一個WorkBook上。我的問題是,如果我有WB最小化和另一個WB打開,並填寫了用戶窗體,數據不會轉儲在最小化的工作簿上。我不確定如何引用特定的WorkBook,以便即使其他WorkBook已打開,它仍會將我的數據轉儲到預期的WorkBook上。這一切可能嗎?如果是這樣,怎麼樣?特定WB上的用戶表單
這裏是我的代碼供參考。
Private Sub cmdSubmit_Click()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
If ActiveWorkbook.MultiUserEditing Then
ActiveWorkbook.AcceptAllChanges
ActiveWorkbook.Save
End If
If txtCallID.Value = "" Then
MsgBox "Please enter a Call ID.", vbExclamation, "CALL ID FIELD ERROR"
'if all fields were answered, show Message Box for confirmation
Else
Dim response As Integer
response = MsgBox("Please review all information before proceeding." & vbCrLf & "Click YES to Proceed, Click NO to review.", _
vbYesNo + vbInformation, "Audit Tracker")
End If
If response = vbYes Then
Dim lRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Data Sheet")
'find first empty row in database
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
If WorksheetFunction.CountIf(ws.Range("E2", ws.Cells(lRow - 1, 1)), Me.txtCallID.Value) > 0 Then
MsgBox "Somebody is already auditing this call", vbCritical, "Duplicate Call ID"
Me.txtCallID.Value = ""
Exit Sub
End If
'check for a segement id
If Trim(Me.txtCallID.Value) = "" Then
Me.txtCallID.SetFocus
MsgBox "Please enter the Call ID"
Exit Sub
End If
'copy the data to the database
With ws
.Cells(lRow, 1).Value = txtDate.Value
.Cells(lRow, 3).Value = Environ$("username")
.Cells(lRow, 5).Value = Me.txtCallID.Value
If ActiveWorkbook.MultiUserEditing Then
ActiveWorkbook.AcceptAllChanges
ActiveWorkbook.Save
End If
'clear the data
Me.txtCallID.Value = ""
Me.txtCallID.SetFocus
End With
End If
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
什麼我希望做的是始終轉儲數據到我的工作簿是DataTracker.xlsd
如果傾銷你的意思是像選擇粘貼的東西比我能理解爲什麼這不起作用。如果你很好地定義你的目標(例如作爲一個範圍對象),這有更好的工作機會。有點難以知道你在做什麼之後......嘗試包括一些代碼。 – Tom
我編輯了我的帖子。我希望你現在可以更好地理解它。 – user5500328