PDA

View Full Version : Word Doc Protect From Excel



josephemery
10-30-2005, 02:42 PM
Hello Everybody hopefully someone can give me a idea of what I am doing wrong. I open a word document from Excel and now I want to protect it, so nothing can be changed. I have a couple different things to get it to work. I tried



WordDocumentName.Protect



But for some reason it won?t work I get a debugging error. So I tried to write a Macro in the Word Document so I can run that would protect it. I got the macro to work in the Word Document. So I been trying to call the Word Marco from the Excel Marco to get it to work. I been using



Application.Run ?WordDocumentName.ModuleName.MacroName?



But for some reason neither way is not working.



I was wondering if it something to do with Excel interface with Word. So if anybody got an idea I be gratefully. Thanks

TonyJollans
10-30-2005, 04:24 PM
Hi Joseph,

I'm not clear exactly what you've done but this should work from Excel - perhaps you can see the difference and work it into your codeSet appWord = CreateObject("Word.Application")
Set docWord = appWord.documents.Add
docWord.Protect 2

The "2" means "wdAllowOnlyFormFields". Protect takes a mandatory argument and I have used the number so that you don't need the reference to Word - if you are using early binding anyway you can use the wdAllowOnlyFormFields constant.

josephemery
10-30-2005, 07:13 PM
Tony,

Thanks very very much the code you posted work perfect. Thanks again. I just need to learn more about excel and word cross over. Thanks once again, you save me from throwing my laptop against the wall.

Joseph

TonyJollans
10-31-2005, 01:16 AM
My pleasure!

All you really need to remember (once you have a reference to the Word Application) is

(a) EVERYTHING in Word must be fully qualified - there are no implicit object references.
(b) Set all object variables to Nothing after you have finished with them (true anyway - but especially true for ones which might be holding on to an automation client)