J
jeanmac
I've been struggling with this for ages, being a VBA novice, and just when
everything seemed to be doing what I wanted it to do, the code suddenly
ignores the fact that I'm telling it to take off the protection in section 2
after Emailing a copy of the document. This is because I want to be able to
edit the original. It was working beautifully - I don't understand. Can
anyone please help??
Code is:
Sub Send_As_Mail_Attachment()
' send the document as an attachment in an Outlook Email message
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
'Prompt the user to save the document
ActiveDocument.SaveAs ("")
'unprotect the two protected sections of the document (need to do this
before protecting all)
ActiveDocument.Unprotect Password:="iknow"
'protect the whole document as read only before sending
ActiveDocument.Sections(1).ProtectedForForms = True
ActiveDocument.Sections(2).ProtectedForForms = True
ActiveDocument.Sections(3).ProtectedForForms = True
ActiveDocument.Protect Password:=" iknow ", NoReset:=False, Type:= _
wdAllowOnlyFormFields
ActiveDocument.Save
'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
' 'Outlook wasn't running, start it from code
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
'Set the recipient for a copy
.CC = "(e-mail address removed)"
'Add the document as an attachment, you can use the .displayname
property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName,
Type:=olByValue, _
DisplayName:="Document as attachment"
.Display
End With
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
'reset protection in the original document
ActiveDocument.Unprotect Password:=" iknow "
'original protection settings
ActiveDocument.Sections(1).ProtectedForForms = True
ActiveDocument.Sections(2).ProtectedForForms = False
ActiveDocument.Sections(3).ProtectedForForms = True
ActiveDocument.Protect Password:=" iknow ", NoReset:=False, Type:= _
wdAllowOnlyFormFields
ActiveDocument.Save
End Sub
everything seemed to be doing what I wanted it to do, the code suddenly
ignores the fact that I'm telling it to take off the protection in section 2
after Emailing a copy of the document. This is because I want to be able to
edit the original. It was working beautifully - I don't understand. Can
anyone please help??
Code is:
Sub Send_As_Mail_Attachment()
' send the document as an attachment in an Outlook Email message
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
'Prompt the user to save the document
ActiveDocument.SaveAs ("")
'unprotect the two protected sections of the document (need to do this
before protecting all)
ActiveDocument.Unprotect Password:="iknow"
'protect the whole document as read only before sending
ActiveDocument.Sections(1).ProtectedForForms = True
ActiveDocument.Sections(2).ProtectedForForms = True
ActiveDocument.Sections(3).ProtectedForForms = True
ActiveDocument.Protect Password:=" iknow ", NoReset:=False, Type:= _
wdAllowOnlyFormFields
ActiveDocument.Save
'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
' 'Outlook wasn't running, start it from code
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
'Set the recipient for a copy
.CC = "(e-mail address removed)"
'Add the document as an attachment, you can use the .displayname
property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName,
Type:=olByValue, _
DisplayName:="Document as attachment"
.Display
End With
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
'reset protection in the original document
ActiveDocument.Unprotect Password:=" iknow "
'original protection settings
ActiveDocument.Sections(1).ProtectedForForms = True
ActiveDocument.Sections(2).ProtectedForForms = False
ActiveDocument.Sections(3).ProtectedForForms = True
ActiveDocument.Protect Password:=" iknow ", NoReset:=False, Type:= _
wdAllowOnlyFormFields
ActiveDocument.Save
End Sub