#1
|
|||
|
|||
VBA to identify how Word was invoked
Hi guys....
Does anyone know if it possible to identify how a Word Document (".docm"/".dotm") was opened from Explorer? By that I mean if was opened by double clicking on it, or RMC and selecting "Open" from the options? I'm interested in this because I tend to write a lot of VBA which is invoked by the User double clicking on the file, and then being presented with various options in order to create/complete various documents. Normally the control is quite tight, so the User is constrained from accessing the VBA via Alt+F11. When developing the code, I normally invoke it from something like "Sub Main_Process" via Alt+F11 and F5, and insert a commented out call to "Main_Process" in "Private Sub Document_Open()" or "Private Sub Document_New()" for templates. When going into Production and uncommenting the call to Main_Process from "Private Sub Document_Open()" the User, and I can no longer access the VBA easily, which means I need to have a "Production" version and an "immediately prior to Production" version which I can get at to amend. I just wondered if I could use the alternate method of opening the document (RMC & Open) to allows access to VBA by detecting it in the "Private Sub Document_Open()" code. Any ideas, or am I barking up a blue herring? |
#2
|
|||
|
|||
I believe it is bark bark. Double clicking and RMC and selecting Open fire the same thing. That is, if the file in Explorer is a document. If it is a template then they fire different things.
Quote:
Quote:
|
#3
|
|||
|
|||
Further details....
Thanks Fumei....
As I suspected, the same process seems to be fired by DC or RMC+Open. So I'll rephrase the original question: When in Document_Open, can I look at some system variable to determine what method was used to open the document? I strongly suspect the answer is "No". As to the next bit, I currently have VBA in Document_Open which immediately shows an Userform etc. So from then on, processing is restricted to options offered to the User. To amend/update the code, I normally access the document's VBA by opening the document, then use Alt+F11, but the above restrictions mean that option is no longer available to me. Therefore, at the moment in Document_Open I detect the current User's name, then, for selected Users (me!), I offer the option of normal processing or VBA access. I was just musing on the idea of simplifying this process.... |
#4
|
|||
|
|||
Quote:
Quote:
You are talking about two separate things. Manually amending code with the VBE (viia Alt-F11) is one thing. Executing code in Document_Open is something else. Perhaps if you tried to explain what you are doing. Why are you amending code? |
#5
|
|||
|
|||
Fumei....
I can't see how to make things clearer! I accept that I cannot (as suspected) interrogate a system variable to determine how Word was invoked. If, in Document_Open the VBA takes control of the User's options and does not allow the User the option of entering the VB Editor, then there is no easy way for the Developer to access the VBE by simply opening the document. (In the processes I am developing the document is created solely from User input to the various Userforms.) Surely, if you've worked in a Production environment you must be aware that as Business needs change, it is often necessary to amend Production code. It is also normal during a development cycle to have User Acceptance Testing of different levels of functionality before the final code is produced and approved. Therefore amendments to code previously deemed to be final (in however temporary a sense) are necessary. I was simply looking for an easier way to maintain two versions of the doment; a "closed" version for the Users, and an "open" version for further development. |
#6
|
|||
|
|||
I worked years in a development and production environment, so I understand that users get a final version. The development version is, well, the development version.
Quote:
2. "and does not allow the User the option of entering the VB Editor". a) well sort of, in that while the code is executing, no, there is no access to the VBE, but only a the fact you can not start it. b) why why why on earth do you want users to access the VBE anyway!!!!??? Quote:
Yes of course users have a "closed" version - and therefore why are they going into the VBE. Yes of course developers have an "open" version for further development. In which case, as long as nothing is actually executing, they have full access to the VBE. |
#7
|
|||
|
|||
I give in
Fumei....
Perhaps you should read my posts more carefully. In Document_Open I take complete control, and never allow the User the option to do anything except make entries on Userforms. When the User selects the final "OK" button a document is created and saved. One reason I do this is to ensure the User DOESN'T have access to the VBE. Please don't bother replying, it's a waste of both our times. |
#8
|
|||
|
|||
Quote:
I did read your posts carefully. you should do the same for me. Quote:
I have developed hundreds (literally) of templates and documents using userforms in a corporate environment. Sorry you are miffed. I was trying to help. But...OK...I will leave you to it then. Last edited by fumei; 04-24-2014 at 05:33 PM. |
Tags |
document options, document properties, vba script |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How do you identify the ID of a picture in PowerPoint? | CatMan | PowerPoint | 4 | 04-17-2012 03:29 PM |
How to identify whether Word 2007 was used to create a document saved as Word 2003 | noviceatwork | Word | 0 | 03-08-2012 06:40 AM |
identify non-members from two lists | rterrain03 | Office | 5 | 12-01-2011 01:41 PM |
how to identify the word files created using Windows or Mac Operating System? | mariaprabudass | Word | 0 | 08-06-2010 05:52 AM |
C# API to identify the uncommitted changes in Excel and Word document? | althafuddeen | Excel | 0 | 04-06-2010 07:40 AM |