Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word 2013 Automation: Runtime Error 4605 2

Status
Not open for further replies.

GhostWolf

Programmer
Jun 27, 2003
290
US
I'm testing one of our vb6 programs against Word 2013, and have run into the subject error message - but haven't yet found a way around it. The program executes:
Code:
Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Open(DocName)
wrdApp.Documents(wrdDoc).Unprotect (password)
which works just fine with Word '03, but results in "the unprotect method or property is not available because this command is not available for reading" in Word '13.

I thought the solution might be as simple as converting the .doc to .docx but, after recompiling, I still get the same error.

Office 2013 isn't available on the development machine, so the reference being used is to Microsoft Word 11.0 Object Library. Could this be a contributing factor?

Any suggestions - short of rewriting?
 
hi,
Code:
Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Open(DocName)
[highlight]wrdDoc.[/highlight]Unprotect (password)
wrdDoc IS your Word document object.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Duuuhhh... a bad-typing moment? I can't explain why I shortened that line. In the code, it actually reads:
Code:
wrdApp.Documents(wrdDoc).Unprotect (password)

Thanks for catchin' that, Skip.
 
I'm actually saying that this is all you need.
Code:
wrdDoc.Unprotect (password)

Your code...
Code:
wrdApp.Documents(wrdDoc).Unprotect (password)
will error, as the Documents collection object, wants an INDEX number within bounds or a valid NAME string as an argument, not another object.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
That didn't work either!

The error message leads me to believe that the document is being opened in Read-only mode, so I thought that changing the read-only state in the open statement
Code:
Set wrdDoc = wrdApp.Documents.Open(DocName, , False)
might resolve that, but it didn't.

I just got a little bit of success, but not enough: modified the Open statement to:
Code:
Set wrdDoc = wrdApp.Documents.Open(DocName, , False, , password)
Now, it's error 6124: "you are not allowed to edit this selection because it is protected."


 
I am confused!

It originally appeared that the error was happening on the Unprotect statement. Now you are saying something different!

Originally you also stated, "I thought the solution might be as simple as converting the .doc to .docx but, after recompiling, I still get the same error."

By performing a SaveAs selecting a SaveAs Type of Word Documant (*.docx) converts your 97-2003 document to a current version document.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Originally, I believe it was happening on the Unprotect statement.

A little research showed me some other parameters to the Open statement, (shown above), which appear to obviate the Unprotect statement - but that gave a different error, (6124).

I have since added the Unprotect statement back into the process, and it's yielding the original error again.

As part of testing, I used Word '03 to remove the protection, then opened the document in Word '13, added the protection back to it and saved it as .docx. The error message is the same whether the program attempts to open the .doc or the .docx.
 
I would try macro recording the required procedure in Word 2003 and then in Word 2013 and note the differences; then apply what you learn to the vb6 code.
 
Well I tried what I suggested but I am afraid I had no luck and got your "the unprotect method or property is not available because this command is not available for reading" in Word 2013, strangely the same code does run under the Word 2013 VBA IDE. The same code being e.g.;
Code:
ActiveDocument.Unprotect "mypassword"
 
Thanks for trying HughLerwill.

That message makes me suspect that the document is being opened in read-only mode, but I haven't discovered anything yet to verify that, or guide me in resolving it.
 
Yes I did a bit more trying today too;
Just for the record. The following vb6 code works on a word doc which has been previously saved protected, in Word 2007 and 2010 but not in 2013.

Code:
Private Sub Command1_Click()

With CreateObject("Word.Application")
    .Visible = True
    With .Documents.Open(App.Path & "\Hello.doc")
        .Unprotect "mypassword"
    End With
End With

End Sub
 
I suspect that "Open e-mail attachments and other uneditable files in reading view" is enabled (Options->General->Start up options)

So you can either manually disable it - or (perhaps temporarily) disable it in your code (Application.Options.allowreadingmode)
 
I've got to admit that I doubted turning off AllowReadingMode was going to be the solution - but I was wrong!

Thank you strongm, my document's now updated.
 
Hello,

My application also has the same problem, i have uncheck "Open e-mail attachments and other uneditable files in reading view" and ran the application it worked.

But i want to do that in vb script, can you please share the syntax to disable it in code

Thanks,
Yogesh Jain
 
You should probably really have asked this in the VBscript forum (forum329). Still, since you're here here's an example ...

Code:
[blue]Dim myWordApp
Dim OldSetting
    
Set myWordApp = CreateObject("Word.Application")
MsgBox myWordApp.Options.AllowReadingMode
OldSetting = myWordApp.Options.AllowReadingMode
myWordApp.Options.AllowReadingMode = False
[green]'Do your stuff here[/green]
myWordApp.Options.AllowReadingMode = OldSetting[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top