我看到之前对这个问题的回答是“您需要将宽度/高度设置为 0”,这 100% 正确,但在较新的 Word 版本中无法做到这一点(至少我看到的不是 - 似乎现在您只能设置线宽,即线条的粗细,而不是形状的宽度),所以我编写了代码来执行此操作。
为了让它为您工作,请将这些添加到您的 Normal 模板(或插件)中的模块中:
Sub Line_Make_Vertical()
Dim shpA As Shape
On Error GoTo ErrHandler
Set shpA = Selection.ShapeRange(1)
If shpA.Type = msoLine Then
If shpA.Height = 0 Then
MsgBox "Line currently has zero height, so can't also set it to zero width!", vbCritical, "ERROR"
Exit Sub
End If
shpA.Width = 0
Else
MsgBox "The selected Shape isn't a line!"
End If
Exit Sub
ErrHandler:
ShowErrorMsg Err, "Line_Make_Vertical", "modShapeHelp"
End Sub
Sub Line_Make_Horizontal()
Dim shpA As Shape
On Error GoTo ErrHandler
Set shpA = Selection.ShapeRange(1)
If shpA.Type = msoLine Then
If shpA.Width = 0 Then
MsgBox "Line is currently zero width, so can't also set it to zero height!", vbCritical, "ERROR"
Exit Sub
End If
shpA.Height = 0
Else
MsgBox "The selected Shape isn't a line!"
End If
Exit Sub
ErrHandler:
ShowErrorMsg Err, "Line_Make_Horizontal", "modShapeHelp"
End Sub
注意我将模块命名为“modShapeHelp”。
我还包括了我的错误消息子程序,他们这样称呼它:
Public Const ADMIN As String = "xxxxxxxxx"
Public Sub ShowErrorMsg(errThis As ErrObject, strSubName As String, strModName As String _
, Optional vbMBStyle As VbMsgBoxStyle = vbCritical, Optional sExtraText As String = "")
If errThis.Number <> 0 Then
MsgBox "An Error Has Occurred in the Add-in. Please inform " & ADMIN & " of this problem." _
& vbCrLf & vbCrLf _
& "Error #: " & errThis.Number & vbCrLf _
& "Description: " & " " & errThis.Description & vbCrLf _
& "Subroutine: " & " " & strSubName & vbCrLf _
& "Module: " & " " & strModName & vbCrLf _
& "Source: " & " " & errThis.Source & vbCrLf & vbCrLf _
& IIf(sExtraText = "", "", sExtraText & vbCrLf & vbCrLf) _
& "Click OK to continue." & vbCrLf & vbCrLf _
& "NOTE: Pressing CTRL-C copies this message to the Clipboard," & vbCrLf _
& "after which pressing CTRL-V will paste it into an email or other" & vbCrLf _
& "destination!", vbMBStyle Or vbSystemModal
End If
End Sub
如果使用常规模板,只需自定义功能区以添加新的顶层功能区(或现有功能区中的组,或将其放在您想要的任何位置),然后从“宏”列表中将这两个添加到该组中。我将它们重命名为“线 - 垂直”和“线 - 水平”。
答案1
简单的方法是按住 键的同时移动线的端点Shift。
然后,Word 会根据您移动光标的方向将线限制为完全水平或垂直。
答案2
这里有几件事:
- 不确定您是如何插入该线的,但即使在最新版本中,我确实有线条“大小”的高度和宽度字段。
- 正如 harrymc 所写,你最好使用Shiftkey。不仅在你第一次插入线时,而且在你使用线的端点更改其长度时
- 可能的情况是,您可能想要调整一条线的角度。在这种情况下,不要只使用线的端点来更改其角度。而是打开尺寸部分的对话框窗口,然后输入适当的角度值。这样,您稍后可以将该角度改回 0°,线将再次变为“直线”。请注意,拖动线的端点不会更改其角度值,因此您始终需要通过对话框窗口。