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
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