PDA

View Full Version : Solved: Password Dialog On Exit



carrrnuttt
06-08-2009, 11:30 AM
Hello all:

I've been reading your forums here for a while now, and I have gotten assistance mostly via searching all your topics. Unfortunately, my latest issue is one that I am unable to search my way out of. This is my first post here, so I hope you take it easy on the FNG.

I have a built a Word macro built into a .dot that walks someone through building a properly-formatted document. The app gets launched by launching the .dot file, which then starts the process. I built an installer package using InstallJammer that creates a shortcut to launch the .dot file.

All of that is functioning as it should. The issue is when the user closes Word after building and saving the document. At times, the project password dialog box pops up when closing Word. Although I don't have specific AutoClose event, I do have ActiveDocument.Save and ThisDocument.Save events that happen during the course of usage. These don't seem to specifically trigger the password dialog issue and seem to be working as expected. I can call the actions that call the saves and close the document, without the issue cropping up.

I guess my question is, what is it that could be causing the password dialog to pop up when closing the document, and how do I suppress it?

With my luck, this is a very simple issue with a simple solution, but for the life of me, I cannot figure it out. I want to almost say that the issue is random, but I know that that's not true.

fumei
06-08-2009, 12:19 PM
1. what is that State flag?????

2. which password dialog? The file itself (Tools > Options > Security), or formfields (Tools > Protect Document...)?

3. "I built an installer package using InstallJammer that creates a shortcut to launch the .dot file." Why? Seems overly elaborate. An icon (pointing to the .dot file) on the desktop works just fine. Or an button on a toolbar in Word itself. Or a keyboard shortcut. All can fire up a .dot file to clone a new document from it.

4. "I do have ActiveDocument.Save and ThisDocument.Save events" Technically, these are not events. These are methods of the objects (ActiveDocument and ThisDocument). That may be quibbling, but I am trying narrow down what may be causing a password dialog. Something must be calling it, and it is not likely those two methods...unless you have some other code that is setting a password setting.

5. "the project password dialog" The project dialog? You mean the VBA project? I doubt that, so I do not know what you mean by "project".

Please describe exactly the password dialog. And, it seems that you are saying it does not happen all the time, just some of the time????

carrrnuttt
06-08-2009, 12:57 PM
1. what is that State flag?????

Arizona. :)



2. which password dialog? The file itself (Tools > Options > Security), or formfields (Tools > Protect Document...)?

5. "the project password dialog" The project dialog? You mean the VBA project? I doubt that, so I do not know what you mean by "project".

Please describe exactly the password dialog. And, it seems that you are saying it does not happen all the time, just some of the time????

2 and 5 have the same answer. Please see my attached image below. I tried to place the image in this space in an img tag, but the forum wouldn't let me. EDIT: "Stratus" is merely my project name, not the app's name, for clarification. I usually name my projects after clouds.

Yes. That is the dialog for when you attempt to access the VBA code behind the macro. And that is what seems to randomly pop up, as if something in my code called out to the password protected VBA environment, and wanted to accomplish something that required a password before closing. If I cancel the dialog, Word closes, everything that's supposed to be saved into the document and the template is saved properly when opened again. No issues.

The dialog seems to pop up at random. I haven't been able to pinpoint a specific thing I am running that might be causing it to pop up. Maybe a setting in Word or the VBA Editor, perhaps?



3. "I built an installer package using InstallJammer that creates a shortcut to launch the .dot file." Why? Seems overly elaborate. An icon (pointing to the .dot file) on the desktop works just fine. Or an button on a toolbar in Word itself. Or a keyboard shortcut. All can fire up a .dot file to clone a new document from it.
The installer package creates shortcuts on the QuickLaunch bar and the Desktop (optional), and creates a Program Folder in Startup with a link also. When Word is opened outside of the template, the application will be out of sight, out of mind. Also, the documents it creates also become un-macro'ed documents when opened outside of the app's process, since the document can be passed on to people who might not have the app.

It also creates an uninstall shortcut.



4. "I do have ActiveDocument.Save and ThisDocument.Save events" Technically, these are not events. These are methods of the objects (ActiveDocument and ThisDocument). That may be quibbling, but I am trying narrow down what may be causing a password dialog. Something must be calling it, and it is not likely those two methods...unless you have some other code that is setting a password setting.

True about the save calls as methods. I meant that I have events that call these methods automatically, such as when I create or delete a DocVar, etc.

No, I don't have any password-generating or soliciting events at all in the macro.

fumei
06-08-2009, 01:32 PM
"True about the save calls as methods. I meant that I have events that call these methods automatically, such as when I create or delete a DocVar, etc."

Huh? Creating or deleting a DocVar most certainly does not automatically call any Save methods. NOTHING calls the Save method automatically. Even clicking the Word "X" close button does not call Save automatically. It calls a messagebox asking what you want to do (if required), and that answer calls Save (or not) explicitly. Save must be used explicitly.

"When Word is opened outside of the template" Huh? I do not know what you mean by that.

"Also, the documents it creates also become un-macro'ed documents "

The "it" refers to the installer. Ummm, "it" does not create ANY documents, and further, documents created from ANY template (.dot file) never have the any macros that may be in the .dot file. ALL documents cloned from a template are clean of any macro code. That is one of the points of .dot files. The .doc files cloned from them point back to the .dot file - the AttachedTemplate - and its macros. So I do not know what you by "become un-macro'ed". Those document should be "macro'ed" in the first place.

Anyway, that is all just yadda yadda quibbling.

Let me see if I have this correct.

1. your project (renamed Stratus) is NOT password protected in the VBE and Locked for viewing. Right?

2. I am stumped. I have no idea whatsoever of what would some times call that password dialog. Further, I can not think of anything would ....wait a second...is there anything, anything at all, in your installer stuff that may be trying to write actual procedure code?

carrrnuttt
06-08-2009, 01:53 PM
"True about the save calls as methods. I meant that I have events that call these methods automatically, such as when I create or delete a DocVar, etc."

Huh? Creating or deleting a DocVar most certainly does not automatically call any Save methods. NOTHING calls the Save method automatically. Even clicking the Word "X" close button does not call Save automatically. It calls a messagebox asking what you want to do (if required), and that answer calls Save (or not) explicitly. Save must be used explicitly.

Sorry I wasn't too clear. I meant that I made methods called AddVar and DeleteVar, and one that combines both methods called ReplaceVarValue that automatically invokes the save method within it, along with the specific codes that create or delete a document variable. Events then call on these methods.


"When Word is opened outside of the template" Huh? I do not know what you mean by that.
Sorry for not being clear here, also. When the macro first runs (when the .dot gets invoked), it asks for 3 things: "Open an existing document," "Create a new document," and "Cancel."

When you choose option one (Open) or two (Create), my custom template automatically becomes the attached template for the opened or created document, and all my add-on's functionality will exist. If you open the same doc just by invoking the document directly or using Word's default open dialog, the template automatically reverts to Normal.dot. Unless an enterprising user somehow copies my macro over to Normal, you'll only get the functions of my macro when you open the document using my macro, accessible via my installer's links or by clicking directly on the template located in the user's Application Data folder in his or her user folder on the machine.

All of this then relates to what's below:


"Also, the documents it creates also become un-macro'ed documents "

The "it" refers to the installer. Ummm, "it" does not create ANY documents, and further, documents created from ANY template (.dot file) never have the any macros that may be in the .dot file. ALL documents cloned from a template are clean of any macro code. That is one of the points of .dot files. The .doc files cloned from them point back to the .dot file - the AttachedTemplate - and its macros. So I do not know what you by "become un-macro'ed". Those document should be "macro'ed" in the first place.
"It" actually refers to my app. Open the documents you created without using my app directly (outside of the app's dialog), and you get a formatted document, but devoid of the document formatting macro, as if you formatted the document manually.


Let me see if I have this correct.

1. your project (renamed Stratus) is NOT password protected in the VBE and Locked for viewing. Right?
The code IS password-protected and locked for viewing. Although, like I said, cancelling the dialog asking for the project password without entering the password doesn't seem to have any ill-effects on the resulting document or the template or code.


2. I am stumped. I have no idea whatsoever of what would some times call that password dialog. Further, I can not think of anything would ....wait a second...is there anything, anything at all, in your installer stuff that may be trying to write actual procedure code?

There is nothing in my installer that attempts to write any additional code. It merely places the template where I want it to go, along with the proper shortcuts to launch it or to uninstall everything cleanly.

fumei
06-08-2009, 02:13 PM
I am trying to follow things.

1. "When the macro first runs (when the .dot gets invoked), it asks for 3 things: "Open an existing document," "Create a new document," and "Cancel."

OK. So "macro first runs" actually means you have instructions in the Document_New event of the .dot file...yes? Those instructions presumably call a userform with those questions on it. Yes? Please try to be VERY specific about things. These questions are...commandbuttons? Or, do I have it wrong, and the instructions in your Document_New ask three separate InputBoxes? Who knows? Again, please try and be very very specific.

In any case, something gets a user response to those three choices. OK.

"If you open the same doc just by invoking the document directly or using Word's default open dialog, the template automatically reverts to Normal.dot."

Ummmm, and how are you doing that?

We seems to be mis-communicating regarding the word "app". By app do you mean the code called by invoking the .dot file? If so, then that has nothing at all to do with your installer stuff. It should execute by, well, invoking the .dot file.

I am missing something.

lucas
06-08-2009, 02:22 PM
Just a quick note that Gerry may have missed. I have not read this thread in detail. If you are using code in a .dot file and use thisdocument in code I believe it will refer to the template and not the clone of the document. You should be using activedocument........

carrrnuttt
06-08-2009, 02:44 PM
I am trying to follow things.

1. "When the macro first runs (when the .dot gets invoked), it asks for 3 things: "Open an existing document," "Create a new document," and "Cancel."

OK. So "macro first runs" actually means you have instructions in the Document_New event of the .dot file...yes? Those instructions presumably call a userform with those questions on it. Yes? Please try to be VERY specific about things. These questions are...commandbuttons? Or, do I have it wrong, and the instructions in your Document_New ask three separate InputBoxes? Who knows? Again, please try and be very very specific.

AutoNew is what makes a call to the UserForm that starts the whole process. AutoNew calls same form that contains the CommandButtons that do, indeed, carry the three choices I was referring to. Pressing one of the buttons either A) creates a new, formatted document that is filled in by subsequent UserForms in my project, B) opens an existing document that was created using this macro, or C) cancels and closes the document (and Word, if necessary).


In any case, something gets a user response to those three choices. OK.

"If you open the same doc just by invoking the document directly or using Word's default open dialog, the template automatically reverts to Normal.dot."

Ummmm, and how are you doing that?
AutoOpen on each document invokes this:


Public Sub AutoOpen()
On Error Resume Next
Select Case Application.Version
Case Is >= 12
ActiveDocument.AttachedTemplate = "Normal.dotm"
ActiveDocument.Save
Case Else
ActiveDocument.AttachedTemplate = "Normal.dot"
ActiveDocument.Save
End Select
End Sub

AutoNew is always what's called when you invoke the template directly, as that always creates a new document instance.


We seems to be mis-communicating regarding the word "app". By app do you mean the code called by invoking the .dot file?
Yes.


If so, then that has nothing at all to do with your installer stuff. It should execute by, well, invoking the .dot file.

You're absolutely right. All the installer is, is a mechanism where I can place my .dot in a specific place on the user's machine (less awkward than distributing the .dot directly), along with creating shortcuts that invoke the template.


Just a quick note that Gerry may have missed. I have not read this thread in detail. If you are using code in a .dot file and use thisdocument in code I believe it will refer to the template and not the clone of the document. You should be using activedocument........
Yes. You are also absolutely correct. I use both ActiveDocument and ThisDocument, as some vars I save within the template as a Global change that carries over to every new document created by the macro, and some vars I want to keep document-specific.

My whole macro in of itself is functioning as I intended it to. It's just that the password dialog popping up seems to be a mystery. It's mostly an annoyance, but of course it's not something I want to pass on to the end-users.

lucas
06-08-2009, 02:58 PM
Yes. You are also absolutely correct. I use both ActiveDocument and ThisDocument, as some vars I save within the template as a Global change that carries over to every new document created by the macro, and some vars I want to keep document-specific.



I'm just thinking that whatever is prompting the password dialog is probably caused by something you are doing that directly effects the template or thisworkbook........just brainstorming while eating dinner....

carrrnuttt
06-08-2009, 04:30 PM
I'm just thinking that whatever is prompting the password dialog is probably caused by something you are doing that directly effects the template or thisworkbook........just brainstorming while eating dinner....

Hmm.

I dug into this line of thought a bit deeper, and it does seem that it is the template changes that prompt the appearance of the dialog (ThisDocument.Save). However, after a couple of cancellations on the password dialog, without ever entering the code in, the dialog doesn't pop up again after recalling the same events that prompt the template save. Now, I didn't say "never," because I haven't tried repeating the processes over and over ad infinitum, but it appears that after cancelling the project password dialog, the same dialog doesn't pop up any longer even if you call on the template save for at least ten times.

Also, this only occurs with Word 2007. On Word 2003, using the exact same template, the issue does not present itself.

I do hope my last statements were clear. I am operating under the weather right now, and my meds make my thoughts a bit scattered.

carrrnuttt
06-08-2009, 06:01 PM
I found something that might be related to the issue I am having: http://www.ozgrid.com/forum/showthread.php?t=12595

I think the issue is there, because when I save the template using ThisDocument.Save, I am saving it as a .dot file, when Word 2007's native format for saving is a .dotx or .dotm. Although creating two installers, one for Word 03 and below (sets up a .dot), and another for Word 07 and up (sets up a .dotm) is not out of the question, I'd really like to see if I can keep this as one installer. Is there any way around this?

I guess I can also tweak the installer to install specific files for specific users (ask the user what his or her version of Word is), but I'd rather solve it from this end, rather than in the installation, if I can.

Anyone else have any insight into this?

fumei
06-09-2009, 12:01 PM
"I think the issue is there, because when I save the template using ThisDocument.Save, I am saving it as a .dot file"

Whoa whoa whoa......THAT implies you are actually opening the .dot file itself.

Are you? You should not be.

carrrnuttt
06-09-2009, 01:32 PM
"I think the issue is there, because when I save the template using ThisDocument.Save, I am saving it as a .dot file"

Whoa whoa whoa......THAT implies you are actually opening the .dot file itself.

Are you? You should not be.

Not necessarily "opening" it. Just saving a variable into it, as opposed to saving a variable into the document initiated by it (which I also do).

fumei
06-10-2009, 08:44 AM
You can not save a variable to it unless you open it. Or if you say you actually can, please let me know how you are doing that.

carrrnuttt
06-16-2009, 01:15 PM
You can not save a variable to it unless you open it. Or if you say you actually can, please let me know how you are doing that.

I guess if I am saving the variable into it, I am technically opening it.

Either way, I solved the issue by simply using System.PrivateProfileString to go ahead and save the little bit of data I was saving into the template, into an entry into "HKEY_CURRENT_USER\Software\Microsoft\Office\Word\Addins\<app_name>" instead.

lucas
06-16-2009, 01:43 PM
So you used the registry to save your variable to? Why not just use a text file?

carrrnuttt
06-16-2009, 02:00 PM
So you used the registry to save your variable to? Why not just use a text file?

It's not just a variable, per se. It's the user's preferred name and institution name that will be the default entry into the title page of every paper that the macro formats for the user. I understand a text file works just as well, but I might reuse the data in later works. It doesn't mean I'm locked into it, though. This project is far from done.

fumei
06-17-2009, 11:00 AM
Why not a document variable?

carrrnuttt
06-17-2009, 12:40 PM
Why not a document variable?

I use those too, to save data into each document generated by the macro-enabled template that's specific to that document (reference lists, etc.). I needed to collect globally default data that will exactly be the same everytime the template is called upon.

fumei
06-17-2009, 01:00 PM
If it is globally default data that is exactly the same...ummm, could that not be data declared as CONST in the .dot file?