V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
hongxii
V2EX  ›  程序员

求 VBA 的操作实例集 word 的

  •  
  •   hongxii · Jan 30, 2020 · 2413 views
    This topic created in 2288 days ago, the information mentioned may be changed or developed.

    如题 感谢各位 想把扫出来的文档综合整理一下格式 对 VBA 不是那么熟悉 目前想要显示每段的文本 但还是失败了 以下内容运行发现 P 的个数只有 1 但是实际上有 10 来段才对 MsgBox 的结果也是空白 所以求个 word 的 VBA 操作实例集合 好照猫画虎 或者求相关网站介绍 MSDN 的 vba 页面地址已有 但是都没有相关的实例 大海捞针

    Sub FindTheWord()
      '显示所有段落的内容
      Dim p As Paragraph, s As String, page As Long
      page = 0
      For Each p In ThisDocument.Paragraphs
        page = page + 1
        s = p.Range.Words(1).Texts
        MsgBox (s)
      Next
      MsgBox ("段落数" & page)
    End Sub
    
    9 replies    2020-01-30 17:47:02 +08:00
    hongxii
        1
    hongxii  
    OP
       Jan 30, 2020
    好吧 刚刚把 ThisDocument 的换成了 ActiveDocument
    就成功显示了

    害 我实在是太菜了
    还是求各种 word 的 vba 操作实例集合 谢谢老哥们
    depress
        2
    depress  
       Jan 30, 2020   ❤️ 3
    微软官方: https://docs.microsoft.com/zh-cn/office/vba/api/overview/word

    一个博客: http://www.exceloffice.net/archives/category/vba/word-vba

    vba 这种东西,需要实现什么就搜什么,提前学没啥用
    loading
        3
    loading  
       Jan 30, 2020
    vba 这么简单,看着语法写就行了。
    forgottencoast
        4
    forgottencoast  
       Jan 30, 2020
    这不是 vba 的问题,这是 Word api 的问题。
    hongxii
        5
    hongxii  
    OP
       Jan 30, 2020
    老哥说的是 确实是这样
    hongxii
        6
    hongxii  
    OP
       Jan 30, 2020
    @loading 话是这么说 有个实例干起来效率总能提升很多 总比在那边死扣文档强
    hongxii
        7
    hongxii  
    OP
       Jan 30, 2020
    @depress 感谢
    hongxii
        8
    hongxii  
    OP
       Jan 30, 2020
    @forgottencoast 老哥说的是 就是 api 有个实例的话分分钟事儿就完了 咋也用不着系统性的全部学完不是
    hongxii
        9
    hongxii  
    OP
       Jan 30, 2020
    @depress 老哥第二个网址棒棒哒!!!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3298 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 14:01 · PVG 22:01 · LAX 07:01 · JFK 10:01
    ♥ Do have faith in what you're doing.