Hi,
In a VB app i am joining .doc into a master document.when i insert the docs the master the formatting changes sometimes is it possible to insert without affectting the formatting.
adhi
Printable View
Hi,
In a VB app i am joining .doc into a master document.when i insert the docs the master the formatting changes sometimes is it possible to insert without affectting the formatting.
adhi
Post your code for inserting.
VB Code:
Public Sub DocOpen(ByVal sFile As String, Optional ViewOnly As Variant, Optional AddToRecentFile As Variant) Dim bViewOnly As Boolean Dim bAddToRecentFile As Boolean On Error GoTo ErrorHandler bViewOnly = False bAddToRecentFile = False If Not IsMissing(ViewOnly) Then bViewOnly = ViewOnly End If If Not IsMissing(AddToRecentFile) Then bAddToRecentFile = AddToRecentFile End If Set m_WordDoc = m_WordApp.Documents.Open(sFile, , bViewOnly, bAddToRecentFile) Set m_WordRange = m_WordDoc.Range If bViewOnly Then m_WordApp.ActiveDocument.Protect wdAllowOnlyComments End If Exit Sub
So your saying that this line is adding a document to the documents collection and changing the formatting?
VB Code:
Set m_WordDoc = m_WordApp.Documents.Open(sFile, , bViewOnly, bAddToRecentFile)
sorry i sent you the wrong code.
VB Code:
Public Sub DocAdd(ByVal sDocfile As String) Dim lEndDoc As Long lEndDoc = m_WordRange.End With m_WordApp.Selection .Move unit:=wdCharacter, Count:=lEndDoc .InsertBreak wdSectionBreakNextPage .Collapse Direction:=wdCollapseEnd .InsertFile sDocfile, , , True Set m_WordRange = m_WordDoc.Range(lEndDoc, m_WordDoc.Range.End) End With End Sub
What if you did a copy/paste? It would then retain the formatting/coloring etc. but then you would have to code in the opening and selection and copying of the to be pasted document.
Yeah...instead Of Inserting File..i May Copy And Paste...that Might Work...let Me Try.
Thanks
I tried doing it...i dont exactly to do it..
need help
Post your code and what is going on. ;)
You suggested ..that instead of inserting file to the master document, to copy/paste. But i dont know exactly how to do it. i tried opening the doc to copy the contents for copy paste...but i dont know how to do it.
the code i posted earlier is the one i used to insert docs into the master document.
adhi
You open another document and select the entire document. Then paste it into the current position in your master document.
Just the basics ...
VB Code:
'Select the entire doc Dim oDoc As Word.Document Set oDoc = m_WordApp.Documents.Open("C:\SomeOtherFile.doc") oDoc.Activate m_WordApp.Selection.WholeStory m_WordApp.Selection.CopyFormat 'Or Selection.Copy m_WordApp.Documents("MasterDocName").Activate m_WordApp.Paste' Or PasteFormat 'Close the other document, etc. oDoc.Close False Set oDoc = Nothing