簡體   English   中英

Excel VBA對象定義的錯誤

[英]excel vba object-defined error

我正在學習excel vba,這個錯誤困擾了幾個小時。 我在這里閱讀了一些解決方案,但無法解決。 此代碼獲取照片路徑,並將照片插入到單元格A1的注釋框中

Sub test()
    Dim TheFile As String
    TheFile = Cells(2, 14).Value

    Range("A1").AddComment
    Range("A1").Comment.Shape.Fill.UserPicture TheFile

End Sub

這具有應用程序定義或對象定義的錯誤。 我檢查“ TheFile”,它返回正確的字符串,即文件路徑

也許您需要使用方括號,或者在添加評論時發生錯誤,但評論已發表

Sub test()
    Dim TheFile As String
    TheFile = Cells(2, 14).Value

    'Only adds a comment if cell don´t already have one
    If Range("A1").Comment Is Nothing Then Range("A1").AddComment           
    Range("A1").Comment.Shape.Fill.UserPicture (TheFile)
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM