【问题标题】:VBS writing to open fileVBS 写入打开文件
【发布时间】:2018-02-17 01:10:16
【问题描述】:

我有一个用户可以输入数据的word文档。我有一个按钮可以运行 VB 来收集信息。我无法让 VB 在打开时将脚本的输出写入文档。 VBS 可以写入打开/活动的 Word 文档吗?对不起,如果这看起来很基本....对 VB 来说是新的。

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    您可以使用方法 - getObject 来设置对已经打开的 Word 文档的引用,如下代码所示:

    Dim word, docs, docName, reqdDoc
    Set word = getObject(,"word.application")
    Set docs = word.documents
    docName = "Document1"                    'Enter the name of the document in which you want to write the data
    'MsgBox docs.count
    For Each doc In docs
        If StrComp(doc.fullName,docName,1)=0 Then
            Set reqdDoc = doc
            Exit For
        End If
    Next
    reqdDoc.Activate
    word.selection.typeText "Hello There:"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-15
      • 2017-08-26
      • 2013-08-16
      • 2023-04-05
      • 2013-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多