【问题标题】:Creating a copy of another a range object in Word using VBA使用 VBA 在 Word 中创建另一个范围对象的副本
【发布时间】:2021-04-25 18:48:38
【问题描述】:

在 Word 中,我试过这个:

Dim Range1 As Range, Range2 As Range
Set Range1 = Selection.Range 'just an example, could be any range
Set Range2 = Range1 'seems to create an alias, not an independent copy
Range2.Collapse 'Not only collapses Range2, but also Range1
Range1.Select 'I had rather keep te original Range1 unaffected

如何创建 Range1 的独立副本?

【问题讨论】:

    标签: vba ms-word copy range alias


    【解决方案1】:

    如果要创建两个 Range 对象,它们指向文档中的同一位置,但可以相互独立地进行操作,请使用

    Set Range2 = Range1.Duplicate
    

    https://docs.microsoft.com/en-us/office/vba/api/word.range.duplicate

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多