Thank you sor far,
I understand that it is easier to merge both documents separately and after
the merge, put the results together. Maybe the answer to the next question
will help me to decide if automating is an option or not:
1. I want to show an Inputbox to read a variable.
This variable is exactly to name of the Excelsheet.
2. I have created a macro to do this for me,
but it gives me an error-message of 'Read-Only'.
This is the source of the macro I tried to create, but which give me errors:
Sub MergeFeedbackDocument()
Dim Code As String
Code = InputBox("Geef your code (e.g. B13R074)", _
"Merge Feedback Document")
Documents.Open _
FileName:="D:\Template_Totals.doc", _
ConfirmConversions:=True, _
Format:=wdOpenFormatAuto
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.Name = "D:\Excelsheets\Feedback_" & Code & ".xls"
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
Windows("D:\Template_Totals.doc").Close savechanges:=False
'Create a new section at a new page for the Detailed Feedback
Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdSectionBreakNextPage
With Selection.PageSetup
.Orientation = wdOrientLandscape
.TopMargin = CentimetersToPoints(0.5)
.BottomMargin = CentimetersToPoints(0.5)
.LeftMargin = CentimetersToPoints(1.5)
.RightMargin = CentimetersToPoints(1.5)
.HeaderDistance = CentimetersToPoints(0.4)
.FooterDistance = CentimetersToPoints(0.4)
.PageWidth = CentimetersToPoints(29.7)
.PageHeight = CentimetersToPoints(21)
.SectionStart = wdSectionNewPage
End With
Documents.Open FileName:="D:\Template_Details.doc", _
ConfirmConversions:=True, _
Format:=wdOpenFormatAuto
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.Name = "D:\Excelsheets\Feedback_" & Code & ".xls"
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^b"
.Replacement.Text = "^m"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.EndKey Unit:=wdStory
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.Copy
ActiveDocument.Close
Selection.PasteAndFormat (wdPasteDefault)
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Count:=1, Name:=""
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^b"
.Replacement.Text = "^m"
.Forward = True
.Wrap = wdFindContinue
End With
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
With Selection.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientLandscape
.HeaderDistance = CentimetersToPoints(0.4)
.FooterDistance = CentimetersToPoints(0.4)
.PageWidth = CentimetersToPoints(29.7)
.PageHeight = CentimetersToPoints(21)
End With
Selection.HomeKey Unit:=wdStory
ActiveDocument.SaveAs _
FileName:="D:\Feedback_" & Code & ".doc", _
FileFormat:=wdFormatDocument
End Sub
Thank you for further help,
Guus