Appending/Deleting a (full page) table in a Word doc

P

Phil H

I have a one page form (table) that I want the end user to be able create a
duplicate form on the next page (new). In addition I want them to be able to
delete it. I have existing code that I found in this site that I have pieced
together to enable me to accomplist this. I works perfectly on one document
but not another.

I am new to Visual Basic and I am using Word 2003.

Am I using the wrong approch? Should I be copying the table instead?

Can someone please explain why it works on one and not on another document
(also a table) and possibly fix the code so it will work on all?

Sub Dupe_pg()
'
' If document is protected, Unprotect it.
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=""
End If

'Copy page 1 and paste to end of document
Selection.HomeKey unit:=wdStory
Selection.Bookmarks("\Page").Range.Copy
Selection.EndKey unit:=wdStory
Selection.Paste

' ReProtect the document.
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub

Sub PageDelete()
Dim sCurPage As String

' If document is protected, Unprotect it.
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=""
End If

'Obtain page number.
sCurPage = Selection.Information(wdActiveEndPageNumber)
If ActiveDocument.Content.ComputeStatistics(wdStatisticPages) < "2" Then
MsgBox "You Can't Delete This Page"
Else
With ActiveDocument
On Error Resume Next
ActiveDocument.Bookmarks("\page").Range.Delete
End With
End If
' ReProtect the document.
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub
 
D

Doug Robbins - Word MVP

I do not see any reason why

Selection.HomeKey unit:=wdStory
Selection.Bookmarks("\Page").Range.Copy
Selection.EndKey unit:=wdStory
Selection.Paste

would work in one document and not the other. You will however get slightly
different results depending upon whether there is only one ¶ after the table
of two. If there is only one ¶, you will end up with only one table in the
document that continues onto the second page. If there are two ¶, you will
have two tables in the document, one on each page.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

Phil H

First, I want to thank you for you response. I did not know about the ¶. The
double ¶ solved the problem.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top