【发布时间】:2020-01-28 18:35:17
【问题描述】:
在 Word 2007 中,我有许多宏作用于选定范围(例如表格中的一行,或随机选择区域(不在表格中)),仅是活动文档的一部分。(它们执行多项任务在同一选择上 - 例如格式化指定的字符串,用制表符替换多个空格,调整图像大小等)
我尝试编写一个输入框程序,允许用户选择范围或检查和修改预先选择的范围(如果他们在执行宏之前忘记这样做,或者需要在宏期间选择特定区域.
输入框好像没有这个功能?
谁能帮忙解决这个问题?
我已经用 InputBox 在 excel 中完成了它,但代码在 Word 中不起作用,并且在 google 上找不到任何有用的东西......
这是 Excel 中的代码,它执行我想要在 word 中执行的操作:
'input box prompt+pause to select range
Set User_RangeSelection = Application.InputBox("select cells to move, with the mouse", Default:=Selection.Address, Type:=8)
If User_RangeSelection Is Nothing Then 'if cancel is clicked - otherwise selects existing cell selection
MsgBox "No Selection made, exiting."
' Exit Sub 'cancels the whole macro after this routine!
End If
'---------------------------------------------------
User_SelectedRange = User_RangeSelection.Address(False, False) 'name the selection as a range
Range(User_SelectedRange).Select 'selects range IN SHEET; OR enter single commands here
'------------------------- Code to execute on/with selection
word 的代码/语法显然完全不同 - 尝试了许多更改,但没有一个得到过去的弹出错误代码。
“TYPE:=8”“未找到命名参数”
删除上述行后,输入框显示实际所选字符串的 1 行位,不显示文档中突出显示的区域,并且不允许单击文档
在“预期:语句结束”末尾添加“as Range”
“地址”-“未找到方法或数据成员”
“范围”“未定义子或函数”
【问题讨论】:
标签: vba ms-word user-input office-2007