zoukankan      html  css  js  c++  java
  • 在WORD中用VBA实现光标移动与内容选择

    在WORD中如何用VBA宏语言选定一行、一段,删除一行、一段,移动光标至行首、行尾、段首、段尾等。

    请看以下内容。Sub MoveToCurrentLineStart()
        '移动光标至当前行首
        Selection.HomeKey unit:=wdLine
    End SubSub MoveToCurrentLineEnd()
        '移动光标至当前行尾
        Selection.EndKey unit:=wdLine
    End SubSub SelectToCurrentLineStart()
        '选择从光标至当前行首的内容
        Selection.HomeKey unit:=wdLine, Extend:=wdExtend
    End SubSub SelectToCurrentLineEnd()
        '选择从光标至当前行尾的内容
        Selection.EndKey unit:=wdLine, Extend:=wdExtend
    End SubSub SelectCurrentLine()
        '选择当前行
        Selection.HomeKey unit:=wdLine
        Selection.EndKey unit:=wdLine, Extend:=wdExtend
    End SubSub MoveToDocStart()
        '移动光标至文档开始
        Selection.HomeKey unit:=wdStory
    End SubSub MoveToDocEnd()
        '移动光标至文档结尾
        Selection.EndKey unit:=wdStory
    End SubSub SelectToDocStart()
        '选择从光标至文档开始的内容
        Selection.HomeKey unit:=wdStory, Extend:=wdExtend
    End SubSub SelectToDocEnd()
        '选择从光标至文档结尾的内容
        Selection.EndKey unit:=wdStory, Extend:=wdExtend
    End SubSub SelectDocAll()
        '选择文档全部内容(从WholeStory可猜出Story应是当前文档的意思)
        Selection.WholeStory
    End SubSub MoveToCurrentParagraphStart()
        '移动光标至当前段落的开始
        Selection.MoveUp unit:=wdParagraph
    End SubSub MoveToCurrentParagraphEnd()
        '移动光标至当前段落的结尾
        Selection.MoveDown unit:=wdParagraph
    End SubSub SelectToCurrentParagraphStart()
        '选择从光标至当前段落开始的内容
        Selection.MoveUp unit:=wdParagraph, Extend:=wdExtend
    End SubSub SelectToCurrentParagraphEnd()
        '选择从光标至当前段落结尾的内容
        Selection.MoveDown unit:=wdParagraph, Extend:=wdExtend
    End SubSub SelectCurrentParagraph()
        '选择光标所在段落的内容
        Selection.MoveUp unit:=wdParagraph
        Selection.MoveDown unit:=wdParagraph, Extend:=wdExtend
    End SubSub DisplaySelectionStartAndEnd()
        '显示选择区的开始与结束的位置,注意:文档第1个字符的位置是0
        MsgBox ("第" & Selection.Start & "个字符至第" & Selection.End & "个字符")
    End SubSub DeleteCurrentLine()
        '删除当前行
        Selection.HomeKey unit:=wdLine
        Selection.EndKey unit:=wdLine, Extend:=wdExtend
        Selection.Delete
    End SubSub DeleteCurrentParagraph()
        '删除当前段落
        Selection.MoveUp unit:=wdParagraph
        Selection.MoveDown unit:=wdParagraph, Extend:=wdExtend
        Selection.Delete
    End Sub

  • 相关阅读:
    2015年新的征程,我的博客开通啦!
    基于USB3.0、DP1.2的网络隔离数据安全传输方案
    USB OTG to PC USB API简介
    SMA2SATA、PCIe2SATA转换模块(也有叫:Sata Test Fixtures)
    SATA接口硬盘加密器
    SVN二次开发——让SVN、TSVN(TortoiseSVN)支持windows的访问控制模型、NTFS ADS(可选数据流、NTFS的安全属性)
    About USB Data Link Cable API
    蓝牙4.0BLE抓包(三) – 扫描请求和扫描响应
    nRF51822外设应用[2]:GPIOTE的应用-按键检测
    蓝牙4.0BLE抓包(二) – 广播包解析
  • 原文地址:https://www.cnblogs.com/zqonline/p/1646362.html
Copyright © 2011-2022 走看看