2010-10-20 296 views

回答

1

您必須執行捕獲錯誤以測試LinkedCell屬性的標準VBA技術。

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工作表上使用四種不同控件的工作證明圖片。

alt text

+0

這是行不通的。 – xiaodai 2010-10-21 05:11:23

+0

@xiaodai,實際上我測試了它,以確保它能工作,當我今天晚些時候開始工作時,我會展示證明。但是,如果你需要幫助,你真的需要付出一點,就像它不適合你一樣。 – 2010-10-21 14:46:11

+0

@xiaodai,好的,我發佈了證明。 – 2010-10-21 18:58:54

0
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: 
相關問題