PDA

View Full Version : How to copy MSWord complete page and create new page in the same Template



sreeni2219
11-02-2009, 01:07 PM
I have a MSWord Template. In the Second Page I have a checkbox, if user clicks on that checkbox i want to copy the second page to a third Page, which means i will have 3 pages now if user clicks on the third page checkbox it should create another same page in the template and focus should be the created page. I have tried to create a macro, really i don't have any luck, Could you please help me to resolve this issue.

lucas
11-02-2009, 01:10 PM
Is this an operation that you might want to use again and again or will it only be to add the 3rd page one time?

sreeni2219
11-02-2009, 01:14 PM
Again & again is the requirement, Or atleast tell me for 3rd page, while copying if we attach Macro to the 3rd page checkbox then it will do automatically.

lucas
11-02-2009, 02:30 PM
I don't know if this will work with the checkbox. Make the sheet you wish to copy current and then run it:


Sub CopyCurrentPage()
Dim r As Range
Set r = ActiveDocument.Bookmarks("\page").Range
With r
.Copy
.Collapse Direction:=wdCollapseEnd
.InsertBreak Type:=wdPageBreak
.Paste
End With
Set r = Nothing
End Sub

go to the second page in the attachment.

fumei
11-03-2009, 09:38 AM
Please clarify if this is indeed a template, or a document created from a template. Also, is the checkbox a formfield checkbox (via the Forms toolbar), or an ActiveX checkbox (via the Controls toolbar).

sreeni2219
11-03-2009, 09:53 AM
First of all thank you very much for your code and it is copying to next page. It is a Template. Whenever user selected the checkbox formfield a macro is called. And the code which you provided is working fine. Thank you very much. Now i end of with 2 issue, After copying the focus is going back to first page of the document, But i want the focus in the current copied page itself and should select the first textbox of the current page and The checkbox should be deselected.
Also how to get list of form fields on the current page of the template,(So atleast if it is checkbox then i will deselect).

sreeni2219
11-03-2009, 10:25 AM
Please see my template. Please goto second page and select the checkbox and tabout, it will create 3rd page, but i want focus should be in the 3rd page of the Name control and 3rd page checkbox should be uncecked, Please help me to resolve this issue.

fumei
11-03-2009, 11:58 AM
1. you are not using Option Explicit. I very strongly suggest that you start using it.

2. why are you coding WordBasic?

3. why are you using so many separate modules? You only need ONE. Having a whole separate module (without Option Explicit)- to contain, and ONLY contain:

Public Const PRSDotPath$ = "./"

seems very odd. Also, this means you do not have to declare the variable Protect in each module. You can do it once. BTW, Protect is always used as a numeric variable, so it should be declared as one...which VBA would make you do if you used Option Explicit.

4. RE: the focus issue, you are turning Protection OFF, doing stuff, and turning it ON. This always returns focus to the first formfield.

5. many of your formfields do not have names (which also means they do not have Bookmarks). This is a bad idea.

6. you use:
Public Const PRSDotPath$ = "./"
yet ALSO use:

Dim PRSDotPath$
in a module. This is confusing, illegal, AND redundant. Which is it? A constant or a variable?

In any case, the checkbox - and its OnExit code does make a new page, and copies the existing page...including of course the checked Checkbox.

What version of Word are you using? The use of WordBasic makes things very difficult to try and fix.

sreeni2219
11-03-2009, 01:30 PM
Thank you, Really it is not my Template, and my manager asked me to fix it. Just i have tried to find a solution, but as per your advice, seems i need to convert the wordbasic code itself. We are using Office2003.