Article ID: 212572 - View products that this article applies to.
This article was previously published under Q212572
When your Visual Basic for Applications macro creates an object variable that is set to reference a picture object, and if your macro later anchors a hyperlink to that same picture object, the object reference is deleted, and the following error message appears:
NOTE: The object itself remains. Only the object reference is deleted from the document.
Run-time error '5825':
Object has been deleted.
For example, the following Visual Basic for Applications macro adds a hyperlink to an already linked picture. The hyperlink is "anchored" to the picture object that is referenced by the InLine Picture object variable oILPic. After the hyperlink is added, the object variable reference oILPic is deleted.
The "Object has been deleted" error message appears because the macro has attempted to access an object that has been deleted (oILPic in the example in the "Symptoms" section of this article). The object may have been deleted deliberately, such as with the Delete method, or it may have been deleted as a side effect of another operation. An example of this is when a frame is added around an inline shape. The original inline shape is deleted, and a copy of the shape is created inside the frame.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:
212536To work around this problem, reference the object directly, as in the following example:
(http://support.microsoft.com/kb/212536/EN-US/ )OFF2000: How to Run Sample Code from Knowledge Base Articles
You can use the IsObjectValid method to verify that an object still exists. The following example demonstrates the use of this method:
For additional information about getting help with Visual Basic for Applications, click the article numbers below to view the articles in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/212623/EN-US/ )WD2000: Macro Programming Resources
(http://support.microsoft.com/kb/226118/EN-US/ )OFF2000: Programming Resources for Visual Basic for Applications