GRCNC
11-01-2016, 02:39 PM
Hi - I'm trying to put together a macro that will open up several files and consolidate them all into 1 file. The macro I'm needing needs to open up the files and bring over an exact copy of the source file. (IE: Layout, formatting, etc needs to stay the same). Additionally, all of the files are 'locked for editing', with certain sections of the file editable and certain sections locked. I've got a great macro (provided by this forum :)) that is bringing over the files into the 1 document. It is working in that: the 'locked for editing' sections are working correctly. However, the layout is not coming over 100% exactly the same. Same sections have double spacing (it shouldn't) thus, sections are being pushed onto an additional page. Here is the code I'm using for this:
Private Sub cmdOK_Click()
'''this macro is working correctly in that the correct areas are locked for editing.
'''this macro is NOT working correctly in that the layout is not coming over 100%.
Dim docProposal As String
docProposal = ActiveDocument.Name
Dim strPath As String
Dim oRng As Range
'Opens the File and inserts the entire document at the current selection
Selection.InsertFile FileName:=strPath & "RFK%20New%20Creator/File%20Intro.docx"
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Selection.InsertParagraphAfter
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.Collapse direction:=wdCollapseEnd
End Sub
So, I tried to change up the code to bring over the formatting correctly. The code below does the exact opposite of the code above. It is bringing over the layout 100% correct, but the entire document is 'locked for editing'. (IE: the ranges that should be available to edit - and is working correctly in the code above - is not working here and locked). Here is the code:
Private Sub cmdOK_Click()
'''this macro is working correctly with bringing over the layout.
'''this macro is NOT working correctly in that the whole document is locked for editing.
Dim docProposal As String
docProposal = ActiveDocument.Name
Dim strPath As String
Dim oRng As Range
'Opens the File and inserts the entire document at the current selection
Documents.Open FileName:=strPath & "RFK%20New%20Creator/File%20Intro.docx", _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
Selection.WholeStory
Selection.Copy
Windows("Blank New Proposal.docm").Activate
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Selection.InsertParagraphAfter
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.Collapse direction:=wdCollapseEnd
End Sub
anybody have any idea what would be causing this? Any advice on how to get both parts working correctly? Not sure why Selection.InserFile would change the layout.
Any help would be GREATLY APPRECIATED. This is driving me crazy...:banghead:
thanks,
GRCNC
Private Sub cmdOK_Click()
'''this macro is working correctly in that the correct areas are locked for editing.
'''this macro is NOT working correctly in that the layout is not coming over 100%.
Dim docProposal As String
docProposal = ActiveDocument.Name
Dim strPath As String
Dim oRng As Range
'Opens the File and inserts the entire document at the current selection
Selection.InsertFile FileName:=strPath & "RFK%20New%20Creator/File%20Intro.docx"
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Selection.InsertParagraphAfter
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.Collapse direction:=wdCollapseEnd
End Sub
So, I tried to change up the code to bring over the formatting correctly. The code below does the exact opposite of the code above. It is bringing over the layout 100% correct, but the entire document is 'locked for editing'. (IE: the ranges that should be available to edit - and is working correctly in the code above - is not working here and locked). Here is the code:
Private Sub cmdOK_Click()
'''this macro is working correctly with bringing over the layout.
'''this macro is NOT working correctly in that the whole document is locked for editing.
Dim docProposal As String
docProposal = ActiveDocument.Name
Dim strPath As String
Dim oRng As Range
'Opens the File and inserts the entire document at the current selection
Documents.Open FileName:=strPath & "RFK%20New%20Creator/File%20Intro.docx", _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
Selection.WholeStory
Selection.Copy
Windows("Blank New Proposal.docm").Activate
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Selection.InsertParagraphAfter
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.Collapse direction:=wdCollapseEnd
End Sub
anybody have any idea what would be causing this? Any advice on how to get both parts working correctly? Not sure why Selection.InserFile would change the layout.
Any help would be GREATLY APPRECIATED. This is driving me crazy...:banghead:
thanks,
GRCNC