Environment: Windows 2003 running under VPC,Office 2007 RTM,VS2005
I have a schema attached to the document in question and here is the code snippet which errors out with a COM exception.
Dim nd As MSWord.XMLNode = wordDoc.XMLNodes.Add("dummyNode", <<namespace>>, CObj(rng))
Dim img As MSWord.InlineShape = nd.Range.InlineShapes.AddPicture("c:\blah.jpg", SaveWithDocument:=True) 'COM Exception occurs here when trying to add a picture
NOTE: The 'rng' object points to a bookmark inside a text box placed under the first page header section
The exact exception trace is shown below:
System.Runtime.InteropServices.COMException was caught
ErrorCode=-2147467259
Message="Error HRESULT E_FAIL has been returned from a call to a COM component."
Source="Microsoft.Office.Interop.Word"
StackTrace:
at Microsoft.Office.Interop.Word.InlineShapes.AddPicture(String FileName, Object& LinkToFile, Object& SaveWithDocument, Object& Range)
at <<Removed the debug source code level stack trace>>
I tried the same using VBA and it worked but with interop scenario it fails. It definitely looks like a regression in Word 2007 because the very same interop code did work properly in Word 2003.
Any quick workaround or a fix would be much appreciated. Thanks in advance.
Cheers
Babu