Results 1 to 24 of 24

Thread: Word plug-in

  1. #1

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611

    Word plug-in

    Is there a way of ensuring that a paticular word file can only be opened in MS word if a given VB app is running?


    Related question - Is there a special format for writing MS word 'plug-ins'?
    Looking for a friendly intelligent chat forum? Visit the white-hart.net

  2. #2
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    I'm not expert at this stuff, so there may be a better way, but what you could do is put VBA code in the Word doc and have that code use the API to figure out what progarms are running and test to see if your VB app is one of them. If your app isn't running, then have the VBA code close the Word file right away.

  3. #3

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611
    Originally posted by phinds
    I'm not expert at this stuff, so there may be a better way, but what you could do is put VBA code in the Word doc and have that code use the API to figure out what progarms are running and test to see if your VB app is one of them. If your app isn't running, then have the VBA code close the Word file right away.
    Any thoughts about how to stop users removing the VBA or stopping it executing?
    Looking for a friendly intelligent chat forum? Visit the white-hart.net

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What are you trying to do? I think most Word 'plug-ins' are some form of activeX object (dll/exe).

    Do you mean a certain word .doc or something that is made to work inside word?

    Your plug-in could encrypt and decypt a file only while it is running so it can't be used if the program isn't running.

  5. #5

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611
    Originally posted by Edneeis
    What are you trying to do? I think most Word 'plug-ins' are some form of activeX object (dll/exe).

    Do you mean a certain word .doc or something that is made to work inside word?

    Your plug-in could encrypt and decypt a file only while it is running so it can't be used if the program isn't running.
    That sounds like the right sort of thing. Can you point me to any examples?
    Looking for a friendly intelligent chat forum? Visit the white-hart.net

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well I don't really have any examples. I've done this at work though. All I did was make ActiveX dll(s) and call them from a Macro on the NORMAL template that loads with all Word documents. Oh and to make things easier I added a Toolbar to Word so the user can just click a button and it fires away.

    Is this something you are planing on selling because installation may be a hassle if so. It was easy where I work because everything could be done through shared network templates and such.

    If this is what you are thinking then I'd start by making the things you need as ActiveX dlls or if you want the user to be able to run them outside of Word as well then ActiveX exes. Once you have that then I'll help you implement it into Word.

    I'm not at work now so I don't have anything handle to send ya, sorry.

  7. #7

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611
    Originally posted by Edneeis
    Well I don't really have any examples. I've done this at work though. All I did was make ActiveX dll(s) and call them from a Macro on the NORMAL template that loads with all Word documents. Oh and to make things easier I added a Toolbar to Word so the user can just click a button and it fires away.

    Is this something you are planing on selling because installation may be a hassle if so. It was easy where I work because everything could be done through shared network templates and such.

    If this is what you are thinking then I'd start by making the things you need as ActiveX dlls or if you want the user to be able to run them outside of Word as well then ActiveX exes. Once you have that then I'll help you implement it into Word.

    I'm not at work now so I don't have anything handle to send ya, sorry.

    Thanks - I've got an activeX exe that already does part of the job - if you do find that you have anything I can learn from I'd be very pleased to see it.
    Looking for a friendly intelligent chat forum? Visit the white-hart.net

  8. #8
    Lively Member
    Join Date
    Jul 2002
    Posts
    69

    Look on the MSDN

    Visual Basic 6 Ent & Pro comes with a project for creating plugins (word, access, excel, IE and so on ) that you can use to have running on startup, on document load etc. The MSDN will walk you through how to make this kind of project into a DLL and register/install it on client machines and such.

    I use this with Excel to create expanded tools menus for people @ work which is better than embedding macro code in the excel since it doesn't bring up a warning every time somebody opens the file about macros possibly having virii
    "Help!!! I've installed Windows CE,ME and NT and now my computer runs like a brick" - shamelessly stolen sig

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Which project Template is it? Or can the Addin template be used for Office Plugins as well? (I always thought it was meant for VB Addins)

  10. #10
    Lively Member
    Join Date
    Jul 2002
    Posts
    69
    Originally posted by Edneeis
    Which project Template is it? Or can the Addin template be used for Office Plugins as well? (I always thought it was meant for VB Addins)
    It does Office as well

    Just go to the Designer in the project and under Application select the app you are editing this for in this case Microsoft Word
    "Help!!! I've installed Windows CE,ME and NT and now my computer runs like a brick" - shamelessly stolen sig

  11. #11
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Right on sdJunky!

  12. #12

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611
    I found the URL on MSDN now that you have told us what to look for!!

    http://msdn.microsoft.com/library/de...eatingInVB.asp

    Looking for a friendly intelligent chat forum? Visit the white-hart.net

  13. #13

  14. #14
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591

    Re: Word plug-in

    Originally posted by Kzin
    Is there a way of ensuring that a paticular word file can only be opened in MS word if a given VB app is running?
    I'm not sure that you can make a Word document completely unaccessable.

    You can do like phinds said--use the AutoOpen macro or Document_Open event to run API to check if the VB app is running. In the VBA editor, right click on the project and select project properties--this will allow you to password protect the VBA code.

    If the document is opened with macro security and the user disables macros, the macros and events wont run and the document will open. Changing the Normal template, adding global templates in the Office StartUp directory, or creating add-ins can get around this--but the user can get around those by deleting or replacing those files. This would make it more difficult for users to get around the security you set up to open the file, but it would still be very very possible.

    If you really really want to prevent the document from opening, I think you would have to only allow the document to be opened from the VB app. That way you can encrypt the actual data in the .doc file so that Word won't be able to read it, but your VB app can decrypt the data and open it in Word. When you decrypt the data, save it (somewhere obscure with an unrecognized name and file extention would be preferable) then use the Word object to open the file. Document save and close events write over the .doc file with encrypted data. Make sure the document is password protected at all times so that even if the user saves or copies the file to another location it will be inaccessable without the password. You can code the VB app to open the document with the password and open unrecognized file extensions.

    Of course if you don't want to be completely obsessed with protection...just put a password on the document, and in the VB app code it to open the document passing the password. Then nobody can open the document unless they know the password or use the VB app to open it. Simple.

  15. #15

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611
    I'm getting a type mismatch with the addin template code - any idea what I'm doing wrong?
    Attached Images Attached Images  
    Looking for a friendly intelligent chat forum? Visit the white-hart.net

  16. #16
    Lively Member
    Join Date
    Jul 2002
    Posts
    69
    It seems that you're not creating a VB Addin but a Microsoft Word.
    due to the Set VBInstance = Application

    If VBInstance is a type of VBIDE and Application is a type of Word.Application then you'll have that issue.

    Ensure that that is what is selected since VBInstance seems to be an instance of a VBIDE.

    Not sure if that's your issue but somewhere to check
    "Help!!! I've installed Windows CE,ME and NT and now my computer runs like a brick" - shamelessly stolen sig

  17. #17

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611
    Originally posted by sdjunky
    It seems that you're not creating a VB Addin but a Microsoft Word.
    due to the Set VBInstance = Application
    That's what I intended! Am I doing the right sort of thing?

    Originally posted by sdjunky


    If VBInstance is a type of VBIDE and Application is a type of Word.Application then you'll have that issue.

    Ensure that that is what is selected since VBInstance seems to be an instance of a VBIDE.

    Not sure if that's your issue but somewhere to check
    How would I declare VBInstance (or its equivalent) if I'm making a word plug-in?
    Looking for a friendly intelligent chat forum? Visit the white-hart.net

  18. #18
    Lively Member
    Join Date
    Jul 2002
    Posts
    69

    How to make the word addin

    First add a reference to the word object library

    Click the menu items
    Project
    References....


    In the dialog browse down and put a check on
    "Microsoft Word 9.0 Object Library"
    The above will be different depending on your version of MS Word e.g. 97 would be different than 2K which would be different than XP and so forth

    Now go into the the Code view of your designer
    and change the line that says
    VB Code:
    1. Public VBInstance             As VBIDE.VBE

    to

    VB Code:
    1. Public VBInstance             As Word.Application

    Note: I would also change the word VBInstance to something like WordInst or so forth but for simplicity sake just change this one item.

    I added a sample zip for you to see how this all works. including using withevents
    Last edited by sdjunky; Sep 5th, 2002 at 11:34 AM.
    "Help!!! I've installed Windows CE,ME and NT and now my computer runs like a brick" - shamelessly stolen sig

  19. #19
    Lively Member
    Join Date
    Jul 2002
    Posts
    69

    Here is the ZIP file

    Here is the ZIP file
    Attached Files Attached Files
    "Help!!! I've installed Windows CE,ME and NT and now my computer runs like a brick" - shamelessly stolen sig

  20. #20

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611

    Re: How to make the word addin

    Originally posted by sdjunky
    First add a reference to the word object library

    Click the menu items
    Project
    References....


    In the dialog browse down and put a check on
    "Microsoft Word 9.0 Object Library"
    The above will be different depending on your version of MS Word e.g. 97 would be different than 2K which would be different than XP and so forth

    Now go into the the Code view of your designer
    and change the line that says
    VB Code:
    1. Public VBInstance             As VBIDE.VBE

    to

    VB Code:
    1. Public VBInstance             As Word.Application

    Note: I would also change the word VBInstance to something like WordInst or so forth but for simplicity sake just change this one item.

    I added a sample zip for you to see how this all works. including using withevents
    Thanks - that's brilliant
    Looking for a friendly intelligent chat forum? Visit the white-hart.net

  21. #21

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611

    Re: Here is the ZIP file

    Originally posted by sdjunky
    Here is the ZIP file
    This is working very well - but one question how do I intercept the document open event to give it a password so that passwords can be put in by the plug-in without the password prompt coming up - a little like


    WdInstance_DocumentBeforeSave

    but for opening it.

    And indeed the clipboard paste event
    Last edited by Kzin; Sep 6th, 2002 at 06:42 AM.
    Looking for a friendly intelligent chat forum? Visit the white-hart.net

  22. #22
    Lively Member
    Join Date
    Jul 2002
    Posts
    69

    Re: Re: Here is the ZIP file

    Originally posted by Kzin
    This is working very well - but one question how do I intercept the document open event to give it a password so that passwords can be put in by the plug-in without the password prompt coming up - a little like


    WdInstance_DocumentBeforeSave

    but for opening it.

    And indeed the clipboard paste event
    You may want to try using the DocumentOpen event. However, is it the case that word is asking for the password before the event?

    If so then perhaps the best method would be to capture the events of the office command bars e.g. Menus. You could then tell if the Open menu has been clicked and so on

    Not exactly sure if that is what you are asking but I hope it helps

    It's a good read in the MSDN on the entire Document Object Heirarchy of Word and the other Office apps to see just what you CAN intercept and work with
    "Help!!! I've installed Windows CE,ME and NT and now my computer runs like a brick" - shamelessly stolen sig

  23. #23

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611

    Re: Re: Re: Here is the ZIP file

    Originally posted by sdjunky
    You may want to try using the DocumentOpen event. However, is it the case that word is asking for the password before the event?
    Thats what I tried but it is asking for the password before the event


    Originally posted by sdjunky


    If so then perhaps the best method would be to capture the events of the office command bars e.g. Menus. You could then tell if the Open menu has been clicked and so on

    Not exactly sure if that is what you are asking but I hope it helps

    It's a good read in the MSDN on the entire Document Object Heirarchy of Word and the other Office apps to see just what you CAN intercept and work with
    Yes that's what I've been working though for the past four hours! The office command bar events look promising if I can work thse out.
    Looking for a friendly intelligent chat forum? Visit the white-hart.net

  24. #24

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611

    Re: Re: Re: Here is the ZIP file

    Originally posted by sdjunky
    You may want to try using the DocumentOpen event. However, is it the case that word is asking for the password before the event?

    A related question - any idea how to trap the document name before it asks for the password?
    Looking for a friendly intelligent chat forum? Visit the white-hart.net

Posting Permissions

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



Click Here to Expand Forum to Full Width