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.
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
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.
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
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
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
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.
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:
Public VBInstance As VBIDE.VBE
to
VB Code:
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
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:
Public VBInstance As VBIDE.VBE
to
VB Code:
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
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
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
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
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