View Single Post
 
Old 10-07-2021, 08:47 AM
mc1903 mc1903 is offline Windows 10 Office 2019
Novice
 
Join Date: Jan 2019
Posts: 8
mc1903 is on a distinguished road
Default

I have mashed two scripts together and have moved on a little bit. Is it kind of working, but its clunky.

I converted all of the simple text tags in each snippet document into Bookmarks. They are now called 'Start_of_Snippet' & 'End_of_Snippet' as {} braces are not allowed.

I added a bookmark in my main document also call 'End_of_Snippet' as it gets over written with each pass of the snippet file import.

Code:
Sub SelectSnippetFiles2()

    Dim mfd As FileDialog
    Dim FileChosen As Integer
    Dim i As Integer
    Set mfd = Application.FileDialog(msoFileDialogFilePicker)
        mfd.InitialView = msoFileDialogViewList
        mfd.AllowMultiSelect = True
    FileChosen = mfd.Show
    
    If FileChosen = -1 Then
        For i = 1 To mfd.SelectedItems.Count
            Debug.Print mfd.SelectedItems(i)
            
            Application.ScreenUpdating = False
            Dim DocSrc As Document, DocTgt As Document, RngSrc As Range, RngTgt As Range
            Set DocTgt = ActiveDocument
            Set DocSrc = Documents.Open(mfd.SelectedItems(i))
            Set RngTgt = DocTgt.Bookmarks("End_of_Snippet").Range
            With DocSrc
              Set RngSrc = .Range(.Bookmarks("Start_of_Snippet").Range.Start, .Bookmarks("End_of_Snippet").Range.End)
              RngTgt.FormattedText = RngSrc.FormattedText
              DocTgt.Bookmarks.Add "Destination", RngTgt
             .Close False
            End With
            Set RngSrc = Nothing: Set RngTgt = Nothing: Set DocSrc = Nothing: Set DocTgt = Nothing
            Application.ScreenUpdating = True

        Next i
    End If

 End Sub
Follow up questions.
  1. Is there a way not to copy the bookmarks from the source (snippets) documents? I just want every thing between the bookmarks.
  2. Is there a way to set a sort order for the multiple file selection? I am thinking there would need to be a interim sort step between the file selection and the copy. Is there a standard sort dialog method?
Again, if anyone could suggest changes/improvements or just offer some kind thoughts and prayers; I would be really grateful.


Thanks
M
Reply With Quote