2014-10-27 76 views
0

我搜索了网页,结果没有如何完成一项简单的任务。 选择一个命名范围。我一直在指定范围内的文本重复,而不是选择。代码注释:Word 2010/2013 VBA - 将选择设置为命名范围

Sub SetSelectionFromRange() 
' Goal: Set current selection to be that of a named range 
' text of doc is "One Two" and at start the insertion bar is between "w" and "o" 
    Dim myRange4 As Range 
    Set myRange4 = ActiveDocument.Range(Start:=0, End:=3) 
    Selection.Range = myRange4.Duplicate   
' result expected is "One" selected and no change in text 
' result actual is "One TwOneo" and insertion bar left after "w" (no selection)` 
End Sub 

回答

0

相反的:

Selection.Range = myRange4.Duplicate 

尝试:

myRange4.Select 
+1

完美。太简单明了,让我看到。非常感谢祖马 – 2014-10-27 01:07:24