我在 Word 中创建了一个表单。它不是 VB 项目中的“userform1”类型。是写在Word文档里的。
我已经能够成功让用户单击提交按钮并通过电子邮件发送表单(MS Word (NightlyReport.DOCM))。
我想让每个文本框成为必需的,如果用户没有输入值,我希望“setFocus”将用户返回到文本框。
由于我没有使用官方“用户表单”,所以我似乎没有此方法可用于将用户返回到表单。
我尝试过:
_改变
_获得焦点
_失去焦点
_按键
_鼠标按下
这些在文本框中起作用。没有一个会将用户发送回该页面。
我有一个简单的表格可以填写并附加到 Outlook。我愿意使用命令按钮验证文本框,但仍然无法将焦点返回到未填写的文本框。
为了简单起见,我只发布了两个文本框和我的基本验证不起作用。需要明确的是,我没有使用用户表单网格,也许这使得这一切变得不可能。
Private Sub txt1_Change()
If txt1.Value = "" Then
MsgBox "need your input"
Else
Exit Sub
End If
End Sub
Private Sub txt2_Change()
If txt2.Value = "" Then
MsgBox "need your input"
Else
Exit Sub
End If
End Sub
尝试以下方法:
Dim iShp As InlineShape, StrOut As String
For Each iShp In ActiveDocument.InlineShapes
With iShp
If .Type = wdInlineShapeOLEControlObject Then
If .OLEFormat.ClassType Like "Forms.TextBox.*" Then
If Trim(.OLEFormat.Object) = "" Then StrOut = StrOut & vbCr & .OLEFormat.Object.Name
End If
End If
End With
Next
If StrOut <> "" Then
MsgBox "The following controls have not been completed: " & StrOut
Exit Sub
End If