VBA select page 2 and copy to end of doc

Max83830 Posted messages 29 Status Member -  
Max83830 Posted messages 29 Status Member -
Hello everyone,
I am starting with VBA in Word.
I would like to create a macro that selects the entire second page, copies it, and pastes it at the end of the document while maintaining the layout.

I am using WORD 2016.
Thank you in advance.

Configuration: Windows / Edge 17.17134

1 answer

  1. cs_Le Pivert Posted messages 8437 Status Contributor 730
     
    1
    1. Max83830 Posted messages 29 Status Member 1
       
      Thanks for the links, I’ve already tried using the macro recorder, but I'm more comfortable with Excel, I need to delve deeper and I'm pressed for time.
      0
    2. cs_Le Pivert Posted messages 8437 Status Contributor 730
       
      You select the beginning of your text: in the Insert Ribbon Bookmark that you name debut
      The end of the text Insert bookmark fin
      You go to the place where you want to paste your text: Insert Bookmark copier

      Here are the macros:

      Sub selectiontexte() 'Declares the names of the bookmarks Const UnSignet As String = "debut" Const DeuxSignet As String = "fin" 'Declares the Range variable Dim Signet1Rge As Range Dim Signet2Rge As Range Dim selection As Range 'Assigns the variables With ActiveDocument Set Signet1Rge = .Bookmarks(UnSignet).Range Set Signet2Rge = .Bookmarks(DeuxSignet).Range 'Assigns the text to be selected '(Text included between the end of the first bookmark 'and the beginning of the second) Set selection = _ .Range(Signet1Rge.End, Signet2Rge.Start) 'selects the text for copying selection.Select selection.Copy 'copies the text End With End Sub Sub copiertexte() 'Declares the name of the bookmark Const Troissignet As String = "copier" 'Declares the Range variable Dim Signet3Rge As Range Dim selection As Range 'Assigns the variable With ActiveDocument Set Signet3Rge = .Bookmarks(Troissignet).Range Set selection = _ .Range(Signet3Rge.Start) 'selects the beginning of the copy selection.Select selection.Paste 'pastes the text End With End Sub 


      There you go

      @+ The Woodpecker
      0
    3. Max83830 Posted messages 29 Status Member 1
       
      Thank you,
      functional macro,
      but would it be possible to make it copy to the line above the bookmark, so that the operation can be repeated as many times as necessary, because during the copy it overwrites the bookmark and the operation can only be done once.
      Thank you in advance
      0
    4. Max83830 Posted messages 29 Status Member 1
       
      Good evening,
      I found a somewhat unconventional way to tackle this problem.
      Two macros, your two modules in one, then I add after having gone down two lines, a macro that inserts your bookmark paste for the next processing. For now, I don't have time to look into it further, but I thank you for your ready-to-use solution.
      0