S
stdavidclarke
I have been working on this far too long so hopefully someone has an
idea about this...
I have a visual basic (6) program that creates a new document, opens
several exiting documents and copies the contents of them into the new
document. It ends up being a report. The problem is this. When one
of the existing documents I open has an attached template containing a
form field (in this case a label control) the document does not seem
to work properly. My code fails the first time I access a property or
method. I have tried this with Word version 2003 and 2007 with the
same result. If I clear the "AttachedTemplate" field in the document
and save it it all works fine (this fix is not a solution as there are
thousands of documents that could potentially be selected for this
report. If I delete the "Label" field from the template it works as
well. The line that fails is: "doc.Content.Copy".
The document I am opening has regular text a a few pictures but has an
"AttachedTemplate" which contains the form field (label control).
Forgive the terrible variable names...
Any help would be GREATLY appreciated.
Dim DocPath As String
Dim qa As Object
Dim aa As Object
Dim doc As Object
Dim nD As Object
Dim Ran As Object
DocPath = "C:\Documents and Settings\clarke david\Desktop
\SomeDoc.doc"
Set qa = CreateObject("Word.Application")
Set aa = CreateObject("Word.Application")
qa.Visible = True
aa.Visible = True
Set doc = qa.Documents.Open(FileName:=DocPath, ReadOnly:=True,
AddToRecentFiles:=False) ' ReadOnly:=True,
Set nD = aa.Documents.Add
If doc.ProtectionType <> -1 Then
doc.UnProtect
End If
doc.Content.Copy
Set Ran = nD.Content
Ran.Collapse (0)
Ran.Paste
idea about this...
I have a visual basic (6) program that creates a new document, opens
several exiting documents and copies the contents of them into the new
document. It ends up being a report. The problem is this. When one
of the existing documents I open has an attached template containing a
form field (in this case a label control) the document does not seem
to work properly. My code fails the first time I access a property or
method. I have tried this with Word version 2003 and 2007 with the
same result. If I clear the "AttachedTemplate" field in the document
and save it it all works fine (this fix is not a solution as there are
thousands of documents that could potentially be selected for this
report. If I delete the "Label" field from the template it works as
well. The line that fails is: "doc.Content.Copy".
The document I am opening has regular text a a few pictures but has an
"AttachedTemplate" which contains the form field (label control).
Forgive the terrible variable names...
Any help would be GREATLY appreciated.
Dim DocPath As String
Dim qa As Object
Dim aa As Object
Dim doc As Object
Dim nD As Object
Dim Ran As Object
DocPath = "C:\Documents and Settings\clarke david\Desktop
\SomeDoc.doc"
Set qa = CreateObject("Word.Application")
Set aa = CreateObject("Word.Application")
qa.Visible = True
aa.Visible = True
Set doc = qa.Documents.Open(FileName:=DocPath, ReadOnly:=True,
AddToRecentFiles:=False) ' ReadOnly:=True,
Set nD = aa.Documents.Add
If doc.ProtectionType <> -1 Then
doc.UnProtect
End If
doc.Content.Copy
Set Ran = nD.Content
Ran.Collapse (0)
Ran.Paste