Consulting

Results 1 to 2 of 2

Thread: Copy and Paste From One Document Into Another

  1. #1

    Copy and Paste From One Document Into Another

    Hi Folks,
    I am looking for some help with creating a macro to copy a lot of text from one document into another.
    I am not asking for anyone to write the whole thing for me - just point me in the right direction into whether this is possible and if so how I could start it.

    In the original document I have text within tables that isn't content controlled and in the document I would like to paste it too it would be content controlled.
    The original document looks a little like the top table, and the second document looks like a little like the bottom table.

    Test Image.jpg

    Is this something that is possible to achieve? To essentially copy the text underneath heading 1 from the first document into content control F1.1 (which is underneath heading 1 in the second document), the text under heading 2 into content control F1.2 etc?

    Any push in the right direction with this would be fantastic.

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    Well yes, I think something would be possible. As a stab:

    Sub StabAtIt()
    Dim oDocS As Document, oDocT As Document
    Dim lngIndex As Long
    Dim oRng As Range
      Set oDocS = Documents(1) 'The doc with the text to copy
      Set oDocT = Documents(2) 'The doc with the CCs
      Set oRng = oDocS.Range
      With oRng.Find
        .Style = "Heading 1"
        While .Execute
          lngIndex = lngIndex + 1
          oRng.Move wdParagraph, 1
          oDocT.SelectContentControlsByTitle("F1." & lngIndex).Item(1).Range.Text = oRng.Paragraphs(1).Range.Text
        Wend
      End With
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •