B
Brent Morris
I was wondering if somebody could help me finish this macro to work
correctly.
Basically what I'm trying to accomplish is to be able to run the envelopes
and labels with a protected document.
I found a macro to spell check a protected document and that worked great,
at http://word.mvps.org/FAQs/MacrosVBA/SpellcheckProtectDoc.htm
I then tried taking this macro and making it work for envelopes and labels.
I came fairly close, I can run the macro and the envelopes and labels dialog
box will pop up and if the user has a name and address it will bring that
into the envelope dialog box. If the user hits print it will print it
correctly and then close the dialog box and then protect the document. If
the user it's cancel they get an run-time error and the document doesn't get
protected.
Here is what I have and maybe if we can get this to work correctly maybe
this could be posted on the MVPS site for "How to enable envelopes and
labels in a protected document"
Option Explicit
Dim Cancelled As Boolean, MyRange As Range, CorrectedError As String
Sub WSNEnvelope()
'
' WSNEnvelope Macro
' Macro created 7/25/2006 by WSN
'
Dim oSection As Section, OriginalRange As Range, oDoc As Document
'If no documents open, quit macro
If Documents.Count = 0 Then
Exit Sub
End If
Set oDoc = ActiveDocument
Set OriginalRange = Selection.Range
System.Cursor = wdCursorWait
'Now unprotect the document
oDoc.Unprotect Password:="wsnforms"
Application.Run Macroname:="ToolsCreateEnvelope"
If Cancelled Then Exit Sub
'Re-protect the document
oDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, _
Password:="wsnforms"
'oDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
OriginalRange.Select
Application.ScreenRefresh
'Release variables from memory
System.Cursor = wdCursorNormal
Cancelled = False
CorrectedError = vbNullString
Set MyRange = Nothing
End Sub
Thanks
Brent Morris
correctly.
Basically what I'm trying to accomplish is to be able to run the envelopes
and labels with a protected document.
I found a macro to spell check a protected document and that worked great,
at http://word.mvps.org/FAQs/MacrosVBA/SpellcheckProtectDoc.htm
I then tried taking this macro and making it work for envelopes and labels.
I came fairly close, I can run the macro and the envelopes and labels dialog
box will pop up and if the user has a name and address it will bring that
into the envelope dialog box. If the user hits print it will print it
correctly and then close the dialog box and then protect the document. If
the user it's cancel they get an run-time error and the document doesn't get
protected.
Here is what I have and maybe if we can get this to work correctly maybe
this could be posted on the MVPS site for "How to enable envelopes and
labels in a protected document"
Option Explicit
Dim Cancelled As Boolean, MyRange As Range, CorrectedError As String
Sub WSNEnvelope()
'
' WSNEnvelope Macro
' Macro created 7/25/2006 by WSN
'
Dim oSection As Section, OriginalRange As Range, oDoc As Document
'If no documents open, quit macro
If Documents.Count = 0 Then
Exit Sub
End If
Set oDoc = ActiveDocument
Set OriginalRange = Selection.Range
System.Cursor = wdCursorWait
'Now unprotect the document
oDoc.Unprotect Password:="wsnforms"
Application.Run Macroname:="ToolsCreateEnvelope"
If Cancelled Then Exit Sub
'Re-protect the document
oDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, _
Password:="wsnforms"
'oDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
OriginalRange.Select
Application.ScreenRefresh
'Release variables from memory
System.Cursor = wdCursorNormal
Cancelled = False
CorrectedError = vbNullString
Set MyRange = Nothing
End Sub
Thanks
Brent Morris