PDA

View Full Version : Solved: Custom Ribbon problem in Doc/docm File



mike009
11-13-2008, 08:32 AM
Hi all,

I have a template that contain a custom ribbon,
Now when i open the template and create a doc or docm file from this template,
the doc or docm file will contain the custom ribbon .

But if i send this file to a friend who has the same ms word version and configuration "security macr enabled ...." the custom ribbon is not in the file any more?

Any idea

Mike

lucas
11-13-2008, 08:56 AM
Mike, you don't seem to understand how Word works on a basic level. If you open the new file on your computer, the ribbon is still there, right?

That is because the new file still has access to the template file which is on your computer. If you move the new file to a different computer where the template file is not located, you will not have the ribbon.

The ribbon is in the template file, not the new file.

Gerry explained this to you here (http://www.vbaexpress.com/forum/showthread.php?t=23484) in post #3.

If you want the ribbon and macro's to accompany the file you are sending out then the ribbon and macro's must be in the document you send and cannot easily be created with a template.

mike009
11-14-2008, 01:08 AM
Thank you ,

Is there is any way to copy all code from the template to any instance of this template?

Regards,
Mike

TonyJollans
11-14-2008, 05:13 AM
I've read this and the other thread and you seem to have a few mixed up issues, and all to do with templates. Please forgive me if I go into too much detail but I want to be clear.


When you create a Document from a Template, the initial document body is copied from the template, and everything else remains only in the Template. That everything else includes (but is not limited to) VBA code, and custom Ribbons in 2007 (which seems to be what you're asking about). In order for those elements to be available when editing the document, the Document is attached to the Template.

The Template attached to a Document has no fancy identification mechanism and Word doesn't search the local computer or the network looking for it. Word knows where to look partly because the full name and path of the Template are stored in the document. If Word doesn't find the template when opening the document, it temporarily attaches Normal.dot (or Normal.dotm in 2007); that attachment, however, is temporary and the document continues to hold the name and path of the original template (with your userid in the path if that's where the template came from) because, next time, the template might be found.


If you don't want to rely on the template, and you want all the various elements of it actually stored in the document, first of all it can't be completely done, as some things can only be kept in templates. But, if you limit yourself to certain components then it may be possible.

I note that you are creating .docm (i.e. macro-enabled) documents in Word-2007 format. As no code is automatially copied from the template, you must be manually adding code to them at the moment. It isn't straightforward, but you can copy code from one document or template to another, if that's what you want. You will need to have the option to trust programmatic access to the VBA Project set under Office Button > Word Options > Trust Centre, and then you can access the VBProject objects. You can read up the Help to find out how to manipulate them, but essentailly you are working with lines of text.

Before going any further, I must just say that custom Ribbons can not be stored in pre-Word 2007 (.doc) documents. Assuming you're actually only doing this in .docx (or .docm) format files, custom Ribbons are stored as xml components of the Word-2007 format package. You cannot access this through VBA so if you really want to copy them you must do it outside the Word environment in the same way you originally created them in the Template (using the Custom UI Editor, perhaps).

All in all, you are making a lot of work for yourself and I can't see a single good reason for it. Just send the document and template together in a folder and everything will work correctly - assuming the recipient doesn't try to open the document directly from an e-mail attachment. This is because the first place Word looks for a template is in the same folder as the document. If it finds one with the same name (ignoring the path) as the attached template, that is the one it will use - again a temporary attachment.

mike009
11-14-2008, 08:26 AM
First i would like to thank you all,

The problem solved,

when not adding the template in the network?
because users must be able to use the template out the company Ex. home.

what the custom ribbon does?
it has some buttons
1- edit some properties logos, owner, company location .... etc
there are 7000 +/- users will use this template in different locations in europe so they will be able to change the document properties thanks to the custom ribbon that calls a macro to run a form for easy usage.

what i did is i attached the template to the template :rotlaugh:
and it did work, don't ask me how, but it did work :rotlaugh:

now if i create a doc file from the template, send this doc file to someone
he can see the custom ribbon and execute macro

again, i saved it as doc not docm

thanks again for your help
Mike