tomaszko
08-16-2017, 08:17 AM
Guys,
I have found a code that merges multiple word documents into one by using folder browser.
Option Explicit
Sub MergeDocs()
Dim rng As Range
Dim MainDoc As Document
Dim strFile As String, strFolder As String
Dim Count As Long
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Pick folder"
.AllowMultiSelect = False
If .Show Then
strFolder = .SelectedItems(1) & Application.PathSeparator
Else
Exit Sub
End If
End With
Count = 0
strFile = Dir$(strFolder & "*.doc") ' can change to .docx
Do Until strFile = ""
WordBasic.DisableAutoMacros 1
If Count = 0 Then
Set MainDoc = Documents.Add(Template:=strFolder & strFile)
Count = Count + 1
Else
Set rng = MainDoc.Range
With rng
.Collapse 0
If Count > 0 Then
.InsertBreak Type:=wdSectionBreakNextPage
.End = MainDoc.Range.End
.Collapse 0
End If
.InsertFile strFolder & strFile
End With
End If
strFile = Dir$()
WordBasic.DisableAutoMacros 0
Loop
MsgBox ("Files are merged")
lbl_Exit:
Exit Sub
End Sub
source: /showthread.php?51797-Macro-to-merge-mulitple-word-doc-into-one-word-doc&p=354802&viewfull=1#post354802
I'm trying to make a UserForm that will contain checkboxes that are "linked" to a specified file in the same location as source file.
Eg. If user marks checkbox A (which is linked to docuemnt A.docx), then marks checkbox B and so on. Then after all checkboxes are marked and "Finish" button is clicked the code above will merge choosed files (by marking checkboxes in UserForm).
I can manage to make UserForm with checkboxes and all but I don't know the way to "link" ckeckbox to a file and then modify code above to merge those files.
Can someone help me and modify code above to merge files that are only marked by checkboxes?
I have found a code that merges multiple word documents into one by using folder browser.
Option Explicit
Sub MergeDocs()
Dim rng As Range
Dim MainDoc As Document
Dim strFile As String, strFolder As String
Dim Count As Long
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Pick folder"
.AllowMultiSelect = False
If .Show Then
strFolder = .SelectedItems(1) & Application.PathSeparator
Else
Exit Sub
End If
End With
Count = 0
strFile = Dir$(strFolder & "*.doc") ' can change to .docx
Do Until strFile = ""
WordBasic.DisableAutoMacros 1
If Count = 0 Then
Set MainDoc = Documents.Add(Template:=strFolder & strFile)
Count = Count + 1
Else
Set rng = MainDoc.Range
With rng
.Collapse 0
If Count > 0 Then
.InsertBreak Type:=wdSectionBreakNextPage
.End = MainDoc.Range.End
.Collapse 0
End If
.InsertFile strFolder & strFile
End With
End If
strFile = Dir$()
WordBasic.DisableAutoMacros 0
Loop
MsgBox ("Files are merged")
lbl_Exit:
Exit Sub
End Sub
source: /showthread.php?51797-Macro-to-merge-mulitple-word-doc-into-one-word-doc&p=354802&viewfull=1#post354802
I'm trying to make a UserForm that will contain checkboxes that are "linked" to a specified file in the same location as source file.
Eg. If user marks checkbox A (which is linked to docuemnt A.docx), then marks checkbox B and so on. Then after all checkboxes are marked and "Finish" button is clicked the code above will merge choosed files (by marking checkboxes in UserForm).
I can manage to make UserForm with checkboxes and all but I don't know the way to "link" ckeckbox to a file and then modify code above to merge those files.
Can someone help me and modify code above to merge files that are only marked by checkboxes?