PDA

View Full Version : Document_Open is too early....



JBrady
09-18-2005, 08:23 PM
Hi All,

I am using an external third party which opens Word within the application. The problem is that on opening the document, I want to run some code to create a toolbar. The third-party product seems to run code after the Document_Open event which removes all toolbars excluding the Standard and Formatting toolbars.

My question is: is there anyway I can get around this to enable my toolbar showing on the opening of the document?

I thought of using a userform and creating the toolbar on the userform_open event and then hiding the userform, but the third-party software will not accept it.

Any ideas on how I can get around this?

Thanks
JB

Anne Troy
09-18-2005, 09:33 PM
JB: Why don't you create a template that contains the needed toolbars, then open THAT instead of "an instance of Word"?

JBrady
09-18-2005, 09:49 PM
Sorry, I guess I wasnt very clear... I have created a template which contains the toolbars and imported it into the third party application.

Within the application, when you click on a button to create the doucment, it opens word, and opens a copy of the template/document that you have imported. At this point, the Document_Open code runs, but the doucment is somehow locked within the third party application (no toolbars visible at all). You must click on an 'Edit' button to do anything in the document. It is at this point that I believe some code runs on Word that makes all toolbars invisible, excluding Standard and Formatting toolbars.

The toolbar I have created is there - you just have to click on View -> Toolbars -> [my toolbar] to see it. Since the users cannot be trusted to do this, I would like the toolbar to appear automatically on launching.

Since it appears that all fields are updated on clicking the Edit button I was thinking about some way of checking if a particular field has been updated (like the TOC)? Any ideas??? I was thinking of a control button on the doucment, but that's pretty ugly, and still not automated....

Thanks
JB

Anne Troy
09-18-2005, 09:53 PM
I'm lost. Are you building this toolbar with VBA code? What is this 3rd-party app? Homegrown? I'm even more confused now than I was before. :)

JBrady
09-18-2005, 09:58 PM
Yes, the toolbars are currently being created using VBA on the Document_Open event.

The problem is that the third party application, which I have no control over, removes all toolbar excluding Standard and Formatting. I have contacted the company that created the third party app, and they have confirmed that this is the case. So I need a work-around to somehow trigger the toolbar to be visible:=true when something happens on the document (eg the TOC being updated).

Have I confused you more? Sorry!

Anne Troy
09-18-2005, 10:06 PM
Nope. My fault. I should'a asked more questions in the beginning. :)
Okay... so how about a MacroButton that says "Click here to activate toolbars", and it's formatted as hidden text so it don't print. Is that possible? Can you, when you run the Doc_open at least ensure that hidden text is displayed? I'm not a coder, but I know Word, and I've been doing VBA project management for several years. Tell the jerks at the 3rd-party to get real. :P

JBrady
09-18-2005, 10:20 PM
Thanks, but I was thinking of something more automated than the users having to hit a button to view the toolbars (who can trust users???)

I have already suggested that the third party change their software for the next version....

Anne Troy
09-18-2005, 10:30 PM
Document_open or _new is the only thing I know of that will occur automatically. Sorry.

JBrady
09-18-2005, 10:46 PM
Thanks.

TonyJollans
09-19-2005, 01:04 AM
It's always difficult working with a third party app, and some trial and error is needed because you don't know excatly what it does.

If I follow you, you must push a button within Word, after Word has initialised (so after all auto macros and open events), to enable editing of an already-open document. If that is the case I doubt there's much you can do except perhaps tailor the standard toolbar and that is fraught with difficulties. Alternatively you might be able to use commandbar events but it wouldn't be easy.

If I've misunderstood please come back. If I am correct you don't really have any point at which you can run code between the app tailoring Word and the app presenting to the user so your options are limited to reaction to user input - either a button of some sort as suggested by Dreamboat, or a reaction to some other user action such as Selection Change but again not easy or entirely reliable as you can't predict when (or, technically, even if) it will be triggered.

I do sympathise with you. I hate apps (including those written by many posters on sites such as this) which try and override user settings. Unfortunately, without the app, I can't try things out.

fumei
09-19-2005, 06:41 AM
1. If the tooolbars are being setup from the template using Document_Open, then this is the incorrect event. Document_Open is the event upon opening the file. If the template is being used to clone a copy, it should be Document_New.

2. If the third party app (and yes, we all dislike them...) is making the instance of Word, exactly WHEN are you getting the template to load?

3. Try playing with a combination of the AutoNew sub as well as the Document)_New sub. I think you may be able to get an event to fire properly.

JBrady
09-19-2005, 03:55 PM
Hi, thanks for the comments.

Tony - yes you have it correct. How can I use Selection Change?

Fumei - I have tried Document_New, AutoNew, Document_Open and AutoOpen - it is using the open events, not the New events. (ps. cute dog!!)

Thanks
Jenny

fumei
09-19-2005, 09:01 PM
There is no Selection Change. What Tony means - I think - is to create a procedure that fires WHEN the selection changes. i.e the user does something to move it. This comes from his comment - "reaction to some other user action such as Selection Change".

I am not quit getting this:

the 3rd party app makes Word open?
it creates a document, but just a new one, NOT from a specified template?

WHERE have you been putting the Autoblahblah etc etc subs???

How do you know it is using the open events?

I photographed the dog in the park outside my house, about two years ago. It was a happy dog.

JBrady
09-19-2005, 09:11 PM
Hi fumei,

Firstly, the doucment/template gets uploaded to the application.

The way the document creation works (as far as I can tell) from the app:
1. the app opens Word within it's own application window (contained within the app).
2. the app saves my template in temp directory (I assume it's saved as a blog inside the app).
3. the app opens my template from the temp directory (where I have all my stuff).
4. the Document_Open event runs (I checked this with msgbox).
5. the app somehow makes the document visible but unable to be edited (no toolbars showing at this stage - it is more like a pdf)

the user gets control at this point

If the user clicks on the 'Edit' button:
6. the app hides all toolbars, excluding Standard and Formatting
7. the app then makes the doucment editable.

Is that more clear for you?
Cheers
JB

fumei
09-19-2005, 11:35 PM
Very clear. Just one last thing. You state "template"...if the events are Document_Open, then this is not template as Word means template. It is a document.

Am I correct that this is NOT loading a .DOT file?

TonyJollans
09-20-2005, 01:23 AM
Hi Jenny,

I'm not sure we can do an awful lot from a distance; this needs trial and error. One thing I would look at: does the app hide all toolbars including those in your document and its attached template - and any other referenced documents? Remember you're trying to find a chink in its armour so try all combinations.

What happens if you try to set a macro to run using OnTIme? Perhaps fire it for ten seconds time in the Document_Open - what happens if it runs before the user is editing? what happens if it runs after the user is editing? Can you tell the difference in code (perhaps by the visibility of toolbars if no other way)? As I say, trial and error :)

fumei
09-20-2005, 06:21 AM
Tony is correct. First of all we need accurate knowledge of what IS happening; and then exactly what you have tried. Have you tried using .OnTime?

MOS MASTER
09-20-2005, 03:53 PM
Hi, :hi:

This sort of thing is always hard (Like the boys already explained) to do but you can always sneak something in.

The easiest thing to do is to copy your code for the toolbar (Or the toolbar itself) in to a code module in Normal.dot (Or other global template)

Then use a simple shortcut to fire your toolbar when you need it. (A toolbar is seldom needed all the time)

I have a lot of those with a shortcut to show the toolbar and to hide it when I need it.

That way you don't need to find out how to break the 3th party apps defenses.

Just try it out I'd say.

HTH, :whistle: