Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-10-2021, 04:26 AM
Trader174 Trader174 is offline Combining Selection of Documents Windows 10 Combining Selection of Documents Office 2016
Novice
Combining Selection of Documents
 
Join Date: Jul 2021
Posts: 4
Trader174 is on a distinguished road
Default Combining Selection of Documents

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
Any help would be gratefully received.
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining Selection of Documents combining word documents 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
Combining Selection of Documents Combining documents of different formats Blaie Word 1 06-04-2011 06:35 PM
Combining Selection of Documents Combining Word Documents dms997 Word 5 02-26-2011 03:25 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:31 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft