VBA 等待 UserForm 的响应并导入到 table BeforeSave?

VBA to wait for response from UserForm and Import to table BeforeSave?

如何让 VBA 等待用户表单“SavePrompt”的响应,然后根据选择(确定或取消)让 VBA 继续?

我需要用户在保存工作簿之前填写一个文本框。

此信息随后将导入到表 1 的 B 列中。 A 列是当前日期和时间。

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim ws As Worksheet
Set ws = Sheets("EDITS")
Dim tbl As ListObject
Set tbl = ws.ListObjects("Table1")
Dim newrow As ListRow
Set newrow = tbl.ListRows.Add

    SavePrompt.Show



With newrow
    .Range(1) = Now
    .Range(2) = TextBox1 'this is from the SavePrompt Userform
End With

End Sub

TextBox1SavePrompt 实例的 属性,不是变量。

而不是这个:

With newrow
    .Range(1) = Now
    .Range(2) = TextBox1 'this is from the SavePrompt Userform
End With

...你应该这样写:

With newrow
    .Range(1) = Now
    .Range(2) = SavePrompt.TextBox1.Text
End With