Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如何使用Visual Basic for Applications从表格单元格复制和粘贴Word(>=2007)公式_Vba_Ms Word_Copy Paste_Equation - Fatal编程技术网

Vba 如何使用Visual Basic for Applications从表格单元格复制和粘贴Word(>=2007)公式

Vba 如何使用Visual Basic for Applications从表格单元格复制和粘贴Word(>=2007)公式,vba,ms-word,copy-paste,equation,Vba,Ms Word,Copy Paste,Equation,我在Word 2010中有一个表格,在第二列有等式。我想从单元格中复制每个等式并粘贴它,例如在文档的开头。但是没有成功。代码如下: Sub CopyEquation() Dim objEq As OMath Set Cols = ActiveDocument.Tables(1).Columns(2) For Each aCell In Cols.Cells objEq = aCell.Range.OMaths(1) 'Runtime error '9

我在Word 2010中有一个表格,在第二列有等式。我想从单元格中复制每个等式并粘贴它,例如在文档的开头。但是没有成功。代码如下:

Sub CopyEquation()
    Dim objEq As OMath

    Set Cols = ActiveDocument.Tables(1).Columns(2)


    For Each aCell In Cols.Cells
       objEq = aCell.Range.OMaths(1)  'Runtime error '91': Object variable or With block variable not set
    Next aCell

    'insert at start of document
    ActiveDocument.Range(0, 0).OMaths.Add objEq  'Runtime error '13': Type mismatch
End Sub

这些错误被称为注释。对于第二个,我使用了一个示例OMath as。

现在我找到了它。这项工作:

Sub CopyEquation()
    Dim objEq As OMath
    Dim objRange As Range

    ' Select first table, second column
    Set Cols = ActiveDocument.Tables(1).Columns(2)

    For Each aCell In Cols.Cells
       ' Copy in each cell the first math environment ...
       Set objEq = aCell.Range.OMaths(1)
       objEq.Range.Copy

       ' ... and paste it at the start of the document
       ActiveDocument.Range(0, 0).Paste
    Next aCell
End Sub

如果您将Set添加到错误行,比如Set-objEq=..,会怎么样?@KazJaw哦,是的。谢谢你回答这个愚蠢的问题。对不起,我是VBA的新手-;在Matlab和Python方面受过更好的培训。