I have created an Excel dashboard that displays the content of an appropriate linked word document in the form of an OLEobject. The links (path & filename) are stored in a list and when an icon (representing a piece of equipment) is clicked, my macro looks up the link and changes the SourceName property of the OLEobject appropriately. This works fine until an invalid link is set (and this is a possibility as I will not be maintaining the list).
When this happens the OLEobject changes into a simple Shape i.e. it ceases to be an OLEobject.
If another icon is clicked which does have a valid path, I would like to programmatically "reset" the shape back to being an OLEobject but can't find a way to do this. I can test to see if the link has been broken by cycling through the OLEobjects collection but that is all.
My OLE object has been named "LinkedWordDoc1". The path & file name of the word document are contained in the string sWordDoc.
Here is the relevant bit of my code:
'test for valid OLEobject - linked word doc
bFound = False
For Each oOLEobj In ActiveSheet.OLEObjects
If oOLEobj.Name = "LinkedWordDoc1" Then
bFound = True
'display associated word doc
If bFound Then
ActiveSheet.OLEObjects("LinkedWordDoc1").SourceName = "Word.Document.12|" & sWordDoc & "!'"
'recreate OLE object
'THIS IS WHERE THE PROBLEM IS!!!!!!!