wadiohead
03-11-2005, 08:38 AM
I have a bit of weird problem. In my work, we have a Word document launching via ActiveX from IE. The problem is, they idiotically protected it--not password, just protection.
That's easy enough to get around by creating a new document and inserting the protected file in. Voila. No protection.
I'd like to automate this via vba and AutoOpen, but I'm encountering annoying problems. When run as a regular Sub, the code works just fine. However, as soon as it's run as AutoOpen, it absolutely refuses to recognize the document as protected.
Sub AutoOpen()
Dim FullyNamed As String
Dim DocumentTitle As String
FullyNamed = ActiveDocument.FullName
DocumentTitle = ActiveDocument.Name
Application.Visible = True
Application.WindowState = wdWindowStateMaximize
'*****
' THIS WOULD GENERATE AN ERROR IF THE DOC WAS PROTECTED: IT DOESN'T IN AUTOOPEN
'*****
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = "asdf"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'**************
If ActiveDocument.ProtectionType <> wdNoProtection Then
Documents.Add DocumentType:=wdNewBlankDocument
Selection.InsertFile FileName:=FullyNamed, Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
On Error Resume Next
Windows(DocumentTitle).Close
End If
End Sub
Thanks so much for your help.
I'm utterly confused.
/edit/ Word 2003 /edit/
That's easy enough to get around by creating a new document and inserting the protected file in. Voila. No protection.
I'd like to automate this via vba and AutoOpen, but I'm encountering annoying problems. When run as a regular Sub, the code works just fine. However, as soon as it's run as AutoOpen, it absolutely refuses to recognize the document as protected.
Sub AutoOpen()
Dim FullyNamed As String
Dim DocumentTitle As String
FullyNamed = ActiveDocument.FullName
DocumentTitle = ActiveDocument.Name
Application.Visible = True
Application.WindowState = wdWindowStateMaximize
'*****
' THIS WOULD GENERATE AN ERROR IF THE DOC WAS PROTECTED: IT DOESN'T IN AUTOOPEN
'*****
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = "asdf"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'**************
If ActiveDocument.ProtectionType <> wdNoProtection Then
Documents.Add DocumentType:=wdNewBlankDocument
Selection.InsertFile FileName:=FullyNamed, Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
On Error Resume Next
Windows(DocumentTitle).Close
End If
End Sub
Thanks so much for your help.
I'm utterly confused.
/edit/ Word 2003 /edit/