Consulting

Results 1 to 4 of 4

Thread: Word Doc Protect From Excel

  1. #1

    Word Doc Protect From Excel

    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

    [VBA]

    WordDocumentName.Protect

    [/VBA]

    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

    [VBA]

    Application.Run ?WordDocumentName.ModuleName.MacroName?

    [/VBA]

    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

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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 code[vba]Set appWord = CreateObject("Word.Application")
    Set docWord = appWord.documents.Add
    docWord.Protect 2[/vba]

    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.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3

    Word Doc Protect From Excel

    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

  4. #4
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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)
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •