I am using VBA to create a word document (.docx). This word document contains plain text content controls as well as picture content controls. I then use VBA to automatically select a picture based on the code below
After the pictures are inserted via my code I save the document using
After the document has been closed down I try to open it again and I am told "The file <filename> cannot be opened because there are problems with the contents."
When I click details it says "Unspecified error" and "Location: Part: /word/document.xml, Line: 2, Column: 0"
If I click ok it says "Word found unreadable content in "<filename>". Do you want to recover the contents of this document? If you turst the source of this document, click Yes.
Clicking Yes opens the document with all the contents and it is now renamed to Document 1. If I click no it does not open.
Please help as I am almost done with my code, just confused why the picture content controls are giving me problems. I can insert the pictures into the content controls manually and I get no errors saving but doing it from VBA gives unreadable content. I have read some about xml stuff but I have no idea what they are talking about. Thanks so much!</filename></filename>
Code:
Set oCC = Word.ActiveDocument.SelectContentControlsByTitle("TabPic").Item(1)
On Error GoTo TabErrorHandler
oCC.Range.InlineShapes.AddPicture Filename:="X:\XFER\ANDREW-T\DCD " & LblVL & "Tabs\" & TermPlt & ".jpg", LinkToFile:=False, _
Range:=oCC.Range, SaveWithDocument:=True
Set oCC = Word.ActiveDocument.SelectContentControlsByTitle("LabelPic").Item(1)
On Error GoTo LabelErrorHandler
oCC.Range.InlineShapes.AddPicture Filename:="X:\XFER\ANDREW-T\DCD " & LblVL & "Labels\E" & LblVE & LblSB & LblPole & ".tif", LinkToFile:=False, _
Range:=oCC.Range, SaveWithDocument:=True
After the pictures are inserted via my code I save the document using
Code:
Set Word = GetObject(, "Word.Application")
doc.Save
After the document has been closed down I try to open it again and I am told "The file <filename> cannot be opened because there are problems with the contents."
When I click details it says "Unspecified error" and "Location: Part: /word/document.xml, Line: 2, Column: 0"
If I click ok it says "Word found unreadable content in "<filename>". Do you want to recover the contents of this document? If you turst the source of this document, click Yes.
Clicking Yes opens the document with all the contents and it is now renamed to Document 1. If I click no it does not open.
Please help as I am almost done with my code, just confused why the picture content controls are giving me problems. I can insert the pictures into the content controls manually and I get no errors saving but doing it from VBA gives unreadable content. I have read some about xml stuff but I have no idea what they are talking about. Thanks so much!</filename></filename>