我已经制作了一个 vbscript 来定位一些计算机并对它们进行 wmi 查询,我的老板希望将这些数据放在一个文档中。问题是该文档是一个 Microsoft Word 文档,其中嵌入了 excel 对象。现在我已经在谷歌上广泛搜索,以任何方式定位和操作内部对象和对象与 OLE,但我似乎无处可去。

所以我对你的问题是,如果有人有一些代码,我可以查看或教程,甚至有可能告诉我它是否可能?

最佳答案

一些注释基于图表是嵌入的 Excel 对象,如第一所述。

''http://msdn.microsoft.com/en-us/library/aa213725(office.11).aspx
''http://msdn.microsoft.com/en-us/library/aa174298(office.11).aspx

    Dim wd ''As Word.Applicatio
    Dim shs ''As InlineShapes
    Dim objChart ''As Excel.Chart
    Dim objSheet ''As Excel.Worksheet
    Dim objOLE ''As Excel.Workbook
    Dim NewSrs ''As Series

    Set wd=CreateObject("Word.Application")
    wd.Documents.Open "C:\Docs\Doc1.docm"
    wd.Visible=True


    Set shs = wd.ActiveDocument.InlineShapes
    ''Just the one shape in this example
    shs(1).OLEFormat.Activate

    ''The OLE Object contained
    Set objOLE = shs(1).OLEFormat.Object

    ''The chart and worksheet
    Set objChart = objOLE.Charts("chart1")
    Set objSheet = objOLE.Worksheets("sheet1")

    objSheet.Range("e1") = "NewData"
    objSheet.Range("e2") = 11
    objSheet.Range("e3") = 12

    Set NewSrs = objChart.SeriesCollection.NewSeries

    With NewSrs
        .Name = "=Sheet1!e1"
        .Values = "=Sheet1!e2:e3"
    End With

MS Graph 的注意事项
''VBA: Reference: Microsoft Graph x.x Object Library
''Graph Object Model: http://msdn.microsoft.com/en-us/library/aa198537(office.10).aspx

Dim shs ''As InlineShapes
Dim objDS ''As Graph.DataSheet
Dim objOLE ''As Graph.Chart

    Set shs = ActiveDocument.InlineShapes

    ''The OLE Object contained
    shs(3).OLEFormat.Activate
    Set objOLE = shs(3).OLEFormat.Object
    Set objDS = objOLE.Application.DataSheet

    ''00=Corners, Row titles = 01,02 ...
    ''Column titles = A0, B0 ...
    ''Cells = A1, B1 ... E9 ...
    objDS.Range("E0") = "New"
    objDS.Range("E1") = 11
    objDS.Range("E2") = 12
    objDS.Range("E3") = 9

Set objDS = Nothing
Set objOLE = Nothing
Set shs = Nothing

关于excel - VBScript 和多级 OLE?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2735218/

10-09 18:08
查看更多