![]() |
#1
|
|||
|
|||
![]()
Hi Everyone
I am new to VBA coding. I have created a word template using content controls for users to fill out with come conditional rules and it works good. I want to be able to create a userform with a selection of document templates that can be selected to be merged into the current document. The only difference in formatting is sometimes the additional page is in portrait and sometimes in landscape. I am taking baby steps here so my first goal is to see if I can get VBA to append a selected file to the current document. All the code examples I have found (such as stickied on this forum) seems to only to be for a folder of documents. What do I need to do to be able to choose a selection of files within a folder, rather than the whole folder? Here is an example of one I tried: Code:
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 Set MainDoc = Documents.Add strFile = Dir$(strFolder & "*.doc") ' can change to .docx Count = 0 Do Until strFile = "" Count = Count + 1 Set rng = MainDoc.Range With rng .Collapse wdCollapseEnd If Count > 1 Then .InsertBreak wdSectionBreakNextPage .End = MainDoc.Range.End .Collapse wdCollapseEnd End If .InsertFile strFolder & strFile End With strFile = Dir$() Loop MsgBox ("Files are merged") lbl_Exit: Exit Sub End Sub |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
jesselscott | Word | 1 | 04-28-2015 09:55 AM |
Combining Word Documents with Comments | kimmers41 | Word | 0 | 05-06-2014 12:56 PM |
Combining/merging documents | hawkeyefxr | Word | 11 | 08-03-2012 03:01 AM |
![]() |
Blaie | Word | 1 | 06-04-2011 06:35 PM |
![]() |
dms997 | Word | 5 | 02-26-2011 03:25 AM |