Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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禁用OLEObject会断开Word 2007中的功能区_Vba_Ms Word_Word 2007 - Fatal编程技术网

使用VBA禁用OLEObject会断开Word 2007中的功能区

使用VBA禁用OLEObject会断开Word 2007中的功能区,vba,ms-word,word-2007,Vba,Ms Word,Word 2007,我正在用VBA编写一个脚本,在文档中嵌入的excel表格中循环。我激活它们,做一些修改,然后继续下一个。之后,我希望再次停用最后一张工作表,并希望光标返回到文档的开头 到目前为止,我有以下代码: Private Sub DeactivateOleObject(ByRef oOleFormat As OLEFormat) On Error Resume Next oOleFormat.ActivateAs "This.Class.Does.Not.Exist" End Sub S

我正在用VBA编写一个脚本,在文档中嵌入的excel表格中循环。我激活它们,做一些修改,然后继续下一个。之后,我希望再次停用最后一张工作表,并希望光标返回到文档的开头

到目前为止,我有以下代码:

Private Sub DeactivateOleObject(ByRef oOleFormat As OLEFormat)
    On Error Resume Next
    oOleFormat.ActivateAs "This.Class.Does.Not.Exist"
End Sub

Sub AutoOpen()
    Dim lNumShapes As Long
    Dim lShapeCnt As Long
    Dim xlApp As Object
    Dim wrdActDoc As Document

    Set wrdActDoc = ActiveDocument

    For lShapeCnt = 1 To wrdActDoc.InlineShapes.Count
        If wrdActDoc.InlineShapes(lShapeCnt).Type = wdInlineShapeEmbeddedOLEObject Then
                Dim oOleFormat As OLEFormat
                Set oOleFormat = wrdActDoc.InlineShapes(lShapeCnt).OLEFormat
                oOleFormat.Activate
                DeactivateOleObject oOleFormat
        End If
    Next lShapeCnt
End Sub
我从你那里借了停用代码。但是,这种禁用方法会破坏Word 2007中的功能区

我可以想象,重新激活主文档会比停用OLEObject更好,但是添加
wrdActDoc.Activate
似乎不能做到这一点

是否可以在不破坏功能区的情况下停用excel工作表?

我不同意用Gary的代码这样的“欺骗”字眼。请参阅我在上的另一篇文章,了解如何安全地停用(但要知道它是
SendKeys
,所以它永远不会100%完美)