VBA select page 2 and copy to end of doc
Max83830
Posted messages
29
Status
Member
-
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
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
-
Hello,
here are 2 sites to get started
use the macro recorder:
https://openclassrooms.com/fr/courses/1438346-redigez-facilement-des-documents-avec-word/1443761-macros-et-vba
and to go further:
https://heureuxoli.developpez.com/office/word/vba-word/
--
@+ The Pivert-
-
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 -
-
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.
-