询问者
word vba 使用AddOLEControl时,当要插入控件的页面存在软回车(shift+enter/ctrl+enter)位置不准确

问题
-
word的vba编程,使用AddOLEControl时,当要插入控件的页面存在软回车(shift+enter/ctrl+enter)位置不准确,控件跳到上面的页面了。
Sub ctrl()
ActiveDocument.ToggleFormsDesign
Dim rg As Word.Range
Set rg = Selection.GoTo(wdGoToPage, wdGoToAbsolute, 2)
ActiveDocument.Shapes.AddOLEControl "forms.checkbox.1", 100, 100, , , rg
End Sub当运行上面代码时,效果如下图:
有什么办法让控件准确地插入到第二页的相应位置上?
- 已移动 Mike Feng 2012年2月8日 6:30 VBA (发件人:Visual Basic)
全部回复
-
Please try this,
ActiveDocument.ToggleFormsDesign
Selection.InsertBreak Type:=wdPageBreak
Dim rg As Word.Range
Set rg = Selection.GoTo(wdGoToPage, wdGoToAbsolute, 2)
ActiveDocument.Shapes.AddOLEControl "forms.checkbox.1", 100, 100, , , rg
亂馬客blog: http://www.dotblogs.com.tw/rainmaker/ -
Please try this,
ActiveDocument.ToggleFormsDesign
Selection.InsertBreak Type:=wdPageBreak
Dim rg As Word.Range
Set rg = Selection.GoTo(wdGoToPage, wdGoToAbsolute, 2)
ActiveDocument.Shapes.AddOLEControl "forms.checkbox.1", 100, 100, , , rg
亂馬客blog: http://www.dotblogs.com.tw/rainmaker/ -
Sorry, 我在word中,直接Run Macro,會在第2頁哦! 還是您是不是在Macro中執行呢!?
Sub Macro1()
'
' Macro1 Macro
'
'
Selection.InsertBreak Type:=wdPageBreak
Dim rg As Word.Range
Set rg = Selection.GoTo(wdGoToPage, wdGoToAbsolute, 2)
ActiveDocument.Shapes.AddOLEControl "forms.checkbox.1", 100, 100, , , rg
End Sub
亂馬客blog: http://www.dotblogs.com.tw/rainmaker/ -
VBA的问题请在这里问: http://social.msdn.microsoft.com/Forums/en-US/isvvba/threads
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.