English 中文(简体)
在VBA中,如何检查OLEObject是否具有LinkedCell属性?
原标题:In VBA how do I check if an OLEObject has a LinkedCell property?
  • 时间:2010-10-20 23:27:29
  •  标签:
  • vba

有没有办法检查OLEObject是否具有LinkedCell属性?例如,标签和按钮没有linkedcells,而其他标签和按钮则有。我正试图编写一段代码,通过循环工作表中的所有OLEObjects来替换linkedcells。提前谢谢。

最佳回答

您必须执行捕捉错误的标准VBA技术来测试LinkedCell属性。

Public Sub test()

Dim cntl As Object
On Error Resume Next

For Each cntl In ActiveSheet.OLEObjects
Debug.Print cntl.Name

If IsError(cntl.LinkedCell) Then
    Debug.Print "No Linked Cell"
Else
    Debug.Print "Linked Cell"
End If

Next cntl

End Sub

以下是在一张空白的Excel表上用四个不同的控件证明它有效的图片。

问题回答
    For Each tempWk In trunkWb.Sheets
            For Each tempShape In tempWk.Shapes

            Set obj = tempShape.OLEFormat.Object

             this bit of code can be confusing but it s necessary
            On Error GoTo LinkedCellNotValid
            With Application.WorksheetFunction
                obj.LinkedCell = .Substitute(obj.LinkedCell, "[" & branchWb.Name & "]", "")

                For j = 1 To i
                    Set oldwk = trunkWb.Worksheets(sheetNames(j - 1))
                    obj.LinkedCell = .Substitute(obj.LinkedCell, "_review_" & j, oldwk.Name)
                Next j
            End With
            GoTo LinkedCellDone
LinkedCellNotValid:
             clear the error
            Err.Clear
            Resume LinkedCellDone

LinkedCellDone:




相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签