Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 10-07-2021, 03:22 PM
Guessed's Avatar
Guessed Guessed is offline Word VBA. How best to insert sections of other documents into a main document. Windows 10 Word VBA. How best to insert sections of other documents into a main document. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I don't like using bookmarks to transfer content or data. Looking at your code for instance, you keep moving the End_of_Snippet so you wouldn't be able to run the macro a second time without removing the additions the first time.

I tend to use Content Controls instead and find them a bit more flexible. For instance, if you have multiple snippets to transfer from each target doc then you could use matching tag and title properties of CCs in both source and target docs to marry content.
Code:
Dim aCC as ContentControl, aCC2 as ContentControl, sTag as String, sTitle as String
  For Each aCC In aDocSrc.SelectContentControlsByTag(sTag)
    sTitle = aCC.Title
    For Each aCC2 In aDocTgt.SelectContentControlsByTitle(sTitle)
      aCC2.Range.FormattedText = aCC.Range.FormattedText  'or add to end if you prefer
    Next
  Next aCC
Sorting the files is a bit involved. You could either save the list to an array (then use a bubblesort function to order) or to a recordset and sort that. I suspect the mfd.SelectedItems is already an array so that makes it probably the most likely contender.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word VBA. How best to insert sections of other documents into a main document. insert multiple word docs into main word doc MimiCush Word 4 03-26-2018 01:07 PM
How to insert a section in the middle of a Word document, but keep the sections around it continuous vspofford Word 3 01-30-2016 01:19 PM
Can Word highlight the same text in the Reviewing Pane as in the main document? wordistheword Word 4 09-09-2013 04:50 AM
How to insert full documents into existing word document Laraak Word 1 03-07-2013 11:59 PM
Connecting documents to main document themangoagent Word 1 08-07-2009 10:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:15 PM.


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