R
robertf2
Using VB6 I have a requirement to create a separate copy of an in-memory word
document on disk (for subsequent processing) without writing overwriting the
original file or changing the name fullpath of the active document(cannot use
..save, this overwites the original, cannot use .saveas as this changes the
filename and this cannot be changed back to the original as .Fullname is a
readonly property).
So, what I though was to clone the document in memory and save the clone to
a temporary file. I have some proof of concept code that appears to work but
what I am worried about is that I am not copying the all the document and .
I see I have to copy the content, the builtindocumentproporties and the
customdocument properties.
Is there anything else that needs to be copied to make sure I have
everything (forms, scripts or whatever)?)
Here is my POC code:
Public Sub CopyDoc(docSource As Word.Document)
Dim docDestination As Word.Document
Dim i As Integer
Dim strProperties As String
Set docDestination = docSource.Application.Documents.Add
docDestination.Content.FormattedText = docSource.Content.FormattedText
' TODO:Temporary exception handler to cope with unset properties
On Error Resume Next
For i = 1 To docSource.BuiltInDocumentProperties.Count
docDestination.BuiltInDocumentProperties.Item(i) =
docSource.BuiltInDocumentProperties.Item(i)
Next i
' TODO: Custom properties
docDestination.SaveAs ("c:\junk1.doc")
docDestination.Close
Set docDestination = Nothing
End Sub
document on disk (for subsequent processing) without writing overwriting the
original file or changing the name fullpath of the active document(cannot use
..save, this overwites the original, cannot use .saveas as this changes the
filename and this cannot be changed back to the original as .Fullname is a
readonly property).
So, what I though was to clone the document in memory and save the clone to
a temporary file. I have some proof of concept code that appears to work but
what I am worried about is that I am not copying the all the document and .
I see I have to copy the content, the builtindocumentproporties and the
customdocument properties.
Is there anything else that needs to be copied to make sure I have
everything (forms, scripts or whatever)?)
Here is my POC code:
Public Sub CopyDoc(docSource As Word.Document)
Dim docDestination As Word.Document
Dim i As Integer
Dim strProperties As String
Set docDestination = docSource.Application.Documents.Add
docDestination.Content.FormattedText = docSource.Content.FormattedText
' TODO:Temporary exception handler to cope with unset properties
On Error Resume Next
For i = 1 To docSource.BuiltInDocumentProperties.Count
docDestination.BuiltInDocumentProperties.Item(i) =
docSource.BuiltInDocumentProperties.Item(i)
Next i
' TODO: Custom properties
docDestination.SaveAs ("c:\junk1.doc")
docDestination.Close
Set docDestination = Nothing
End Sub