PDA

View Full Version : toolbars



northernstar
08-20-2007, 10:47 PM
hi everyone

i would like to add custom buttons and menus to the toolbar in word, which i can do quite easily but i am looking for a quicker way of doing it on several machines on the same network

at the moment i am writing the code and saving it to the network then physically going round all of the machines and adding the buttons & menus on each pc

any help would be much appreciated

many thanks

lucas
08-21-2007, 06:06 AM
I think you can put your menu and code in a word document and then save it as a template file .dot and save that file to the network and and everyone can link to it as a global template. That also helps if you wish to change it...you only have to change one file.

Anne Troy
08-21-2007, 07:53 PM
Tools-->Options, File Locations tab. Make sure everyone has the same location for Workgroup templates. Store the DOT file in there.

(Hi, Steve!)

northernstar
08-21-2007, 10:43 PM
thanks for that

not too sure how templates work?

but we already have the word documents made up for the work we do and i would like the custom buttons and toolbars to work for each of the these word documents on each pc

sorry if i didnt explain it properly the first time, hope this helps

thanks again

Anne Troy
08-21-2007, 10:48 PM
How templates work (or at least SOME information):
http://www.officearticles.com/word/template_tips_for_microsoft_word.htm

:)

lucas
08-22-2007, 05:28 AM
Hi Anne,
Long time no see. :hi:

fumei
08-22-2007, 07:54 AM
northernstar, the best way is as Steve suggests. Put your stuff in a .dot file and load it as a global template.

Note that putting it in the Workgroup templates folder will not load it as a global. In fact, it does NOT have to be in the Workgroups folder. It could be anywhere, depending on your circumstances.

It could be anywhere, and loaded as global dynamically. Or, to have it load automatically, put the .dot file in the Office Startup folder.

You do not need to go round and add the buttons on each PC. How exactly are you doing that anyway? Are you changing each PC normal.dot? If so, this is not the best thing to do.

Again, put your stuff into a .dot file and either:

1. put that file into Startup on each PC; OR

2. put that file into a network folder (it does not matter where), and point to it via code (ie. load it dynamically) from each PC normal.dot.

Anne Troy
08-22-2007, 08:57 AM
LOL. Gerry is right. Don't know what I was thinking!
Right... he can change the Startup folder of all the PCs to go to a specific location...

northernstar
08-31-2007, 07:38 AM
hi everyone

i will try and explain this problem as clearly as possible first time

here goes....

i have wrote some code to perform some simple tasks and i had then created a custom toolbar which works fine but now i would like to make this toolbar available across the network

can this be done?

thanks

northernstar
08-31-2007, 08:06 AM
hi

i dont understand the global template and loading it dynamically or how to direct word via code to a new template

please help me

lucas
08-31-2007, 08:18 AM
Threads merged.
You should not start a new thread to ask the same question. Better if all the input from both directions are in the same thread.

On to your problem.


can this be done?

Yes
Now northstar if you really want help you must answer questions and you must try the advice given and if you don't understand you must ask questions.

The solution to your problem requires the use of a template.


not too sure how templates work?
If you're going to work with word and solve this problem....guess what? Your going to learn a little about templates.


but we already have the word documents made up for the work we do and i would like the custom buttons and toolbars to work for each of the these word documents on each pc

Question 1: Let's just take one of these documents and work through it. i suspect that when you see how this works that you will want to combine them all into one template.

Does the document contain the macros you want to run....can you verify for me that they are not in your normal dot. It would be nice if you would upload one of these files.

Question 2: Are the toolbar and buttons created in the document above and not in the normal.dot
When you create your toolbar you should get the dialog box that you see at the bottom of this post and if when you create it the box says normal.dot then you are not attaching the toolbar to the open document so you must drop the box and make sure it reads the name of the file you want the toolbar in.

One way we can determine if the toolbar is attached to your document...does the toolbar show with every document you open in Word? If so then it's probably saved in your normal.dot.

After you get those problems worked out all you have to do is save the document as a template file...go to file saveas and select template.

Save it to your hard drive somewhere and then copy the .dot file you have created and put a copy of it on the network.
Have each person set their Word startup directory for that network folder....something you will just have to do once but after that if you want to change your template file just change the one in the network folder and you're done.

To find the startup folder in word go to Tools-options-file locations. Select the line that says Startup and click the modify button at the bottom of the dialog box.

fumei
08-31-2007, 11:56 AM
Sigh.

northernstar
09-02-2007, 02:55 PM
answer 1 - the only macros i have are in a custom toolbar, not sure what you mean when you ask if the files are in my normal.dot?? yes i would like all of the files combined into this template providing it doesnt mean rewriting ot copy them into this template (unless there is a quick way as i have hundreds of these) and they have all been made up on many different pcs

answer 2 - i have setup a custom toolbar which stays open as long as i have ticked it on the dropdown menu, but if i unclick it then open a new or existing file then it doesnt appear

hope this helps

lucas
09-02-2007, 03:01 PM
Please attach your file. Go to post reply at the bottom left of the last post and when you get your message typed scroll down and look for manage attachments...you may have to zip it up if it too big.

northernstar
09-02-2007, 03:14 PM
every file that we have is different and i dont have any here at the moment as i am at home and not work. can try and upload one tomorrow at some point.

i have tried to listen to all your advice and put it into practise but i am finding it very difficult as i am very new to advanced word and word vba (literall a day or two before i registered on here) and i have never used templates or any vba just ordinary word documents which have been made up by other people.

i also find that the people on here speak and give out advice as if the person is quite well up on the subject they are asking about, not sure about others but in my case this is very much NOT the case

so by creating a new template would this mean all of the existing documents will need re doing or can this be applying the template?

thanks

northernstar
09-02-2007, 11:00 PM
please find attached the file i would or may like to use as a template

it doesnt have the toolbars attached to it, but i hope it helps

thanks

lucas
09-03-2007, 09:33 AM
We will need one with the toolbars attached and the macros' included.

northernstar
09-03-2007, 01:16 PM
will sort one out in the morning from work

how would i apply this template to hundreds of documents already setup as normal documents?

northernstar
09-03-2007, 01:24 PM
will do when i get back into work tomorrow

will i be able top apply this template to all of the existing files of already made up normal documents?

thanks

lucas
09-03-2007, 02:17 PM
Not apply the template but yes you will be able to run the code that's in it on other documents if the code is written correctly. But you have a ways to go first...one step at a time.

fumei
09-03-2007, 10:44 PM
Sorry, but IMO, if you do not have a solid basic knowledge of how Word works, then what on earth are you doing working with macros and hundreds of files?


answer 1 - the only macros i have are in a custom toolbar, not sure what you mean when you ask if the files are in my normal.dot?? yes i would like all of the files combined into this template providing it doesnt mean rewriting ot copy them into this template (unless there is a quick way as i have hundreds of these) and they have all been made up on many different pcs

The above statement is so full of misconceptions, and misunderstandings that I am almost speechless.

1. You MUST learn to understand where VBA code is. The statement above clearly shows you have no idea where code is, or where it is run from.

"the only macros i have are in a custom toolbar"

WRONG, WRONG, WRONG.

Macros (procedures) are not in toolbars. The objects (icons, buttons, menu etc.) in toolbars are pointers to procedures. Procedures are in code modules.

2. Code modules can be in four places:

normal.dot
the attached template
a global template
the document itself

3. Recorded macros by default are written to normal.dot. This is a Microsoft decision. However, even Microsoft itself states that this is NOT a good idea. Normal.dot gets corrupted easily. Whenever possible, procedures should be written to a template file, but NOT the normal.dot template file.

4. Efficient and proper use of Word revolves around templates. Actually understanding this is crucial. From the quote above:

"yes i would like all of the files combined into this template providing it doesnt mean rewriting ot copy them into this template "

What do you mean "rewriting"? And you do not "copy" into a template. I have no idea what you mean by "combined". Again, you clearly do not understand the basic structure of Word.

ALL documents use a template. If one is not explicitly attached, then Word uses normal.dot. As normal.dot does, in fact, get corrupted easily, best-practice demands that you use an explicit template when creating documents.

Yes, you can certainly apply ("attach") a template to hundreds of document if you want. There is a method to do so.Sub AttachABunch()
Dim file
Dim FilePath As String
FilePath = "C:\whatever\"
file = Dir(FilePath & "*.doc")
Do While file <> ""
Documents.Open FileName:=FilePath & file
With ActiveDocument
.AttachedTemplate = "C:\Templates\Letter.dot"
.Save
.Close
End With
file = Dir
Loop
End SubThis would open every .doc file in the c:\whatever folder and attach the template Letter.dot to each document.

Note that the template file (letter.dot) can be anywhere. It does not have to be the the Workgroup folder, or the userTemplate folder. It can be anywhere.

Once attached, ANY code in that template will be accessible to the document.

In terms of code accessibility, here is how it goes:

Code in normal.dot - can be executed in any document.

Code in a loaded global template - can be executed from any document.

Code in the attached template - can be executed from any document created by that template, or any document that has had the template attached to it.

Code in the document itself - can be executed only from that document.

Let's see if I can make this very clear.

Your question (if I understand this correctly) is this:

How do I have a bunch of existing documents to show a NEW toolbar?

There are a couple of answers, and which one is appropriate depends on EXACTLY the situation regarding those documents, and your network.

1. Make a template file and open all those files, and attach it.

2. Make a global template and then have each PC's normal.dot load it. You can also use Windows OS level scripting to do this.

3. Put the toolbar in each PC's normal.dot.

Look, I know it may seem like I am being hypercritical, but you have to do some work. I spend hours and hours of my own time helping people here and on other forums. The point is YOU have to do some work.

If you are going to try and do advanced work with Word, you MUST work at understanding Word. How can it be otherwise? Also remember that all of us, myself included, all started from scratch. We all started not knowing anything. We got to know things by hard persistent work.

And...it is not easy. The Word Object Model can be very very weird at times. The point is though is that no person can do serious advanced Word VBA without understanding Word.

And it is an on-going learning. It never stops. I am still learning, still finding stuff out that I had no clue about.

So relax, and think about what you are posting. Do as much research as possible. Use Help constantly. And please, really, think about what you are posting. Here is an example:
i have setup a custom toolbar which stays open as long as i have ticked it on the dropdown menu, but if i unclick it then open a new or existing file then it doesnt appear

Read that. Read it again.

WHAT "dropdown menu"? How did it get there? What is on that menu? "stays open"???? What does that mean? A toolbar is not "open". It is visible, or not visible. Is this dropdown menu on the View menu? Is your toolbar listed there? If you unclick it - thus making it not visible - why on earth would you expect any new document to have it visible?

It would be visible in any new document if it was properly in a global template, or normal.dot.

Which is why....learn about templates. THAT is where your code is.

Think. Good questions will never be ignored.

northernstar
09-03-2007, 11:12 PM
here is a file which has the code in which i am using

fumei
09-04-2007, 12:20 AM
That file is useless and pointless to the question you are asking.

There are no toolbars which is - if you look at the title of YOUR thread - rather the point, is it not?

The multiple Subs is VERY bad coding form.

You have no way to even start any processes at all. Never mind any toolbars.

WHAT toolbars????

You are making a .dot file, a template, but you have NO CODE to execute anything when you make a new document from it!

If you make a new document from this template absolutely nothing will happen.

You do not even have any way to choose any of those Subs.

All those separate Subs with the ChangeFileOpenDirectory - you have 12 of them - can be done with ONE Sub. Learn to use arrays.

Learn to use constants.

But back to what you posted, what YOU asked. There is nothing regarding toolbars in this file whatsoever.

You are wasting my time. I don't care about the code you are using. It is not very good code. I actually DO care about helping you make better code. And I really DO care about helping answering reasonable and accurate questions. You are doing neither.

Do you want to know about toolbars and how to use them. Then show me. This file has nothing of any relevance to this thread. It is more than useless, it is annoying.

I will repeat it: if you make a new document from this template nothing will happen. You will get a blank document. How very useful. How are you going to get a user to execute anything?

How are you going to get

Sub General(), or
Sub STANDARD(), or
Sub SPECIFIEDMICS(), or
Sub SPECIFIEDVERNIERS(), or
Sub SPECIFIED()

to run? NOTHING will run unless you tell it to do so. And you don't.

And there is nothing at all with toolbars here.

You mentioned:

" have setup a custom toolbar "

Not in this file there isn't. Which again makes this more than useless, it is annoying and a waste of my time. I have tried to help, and I would help if I could. But there seems to be nothing I can do.

northernstar
09-04-2007, 04:32 AM
sorry if you think i am wasting your time.....that is not my intention

i thought that the toolbar was saved to that file which was a template and not a .doc file???

i am very keen on making my code better as i know its not that good but i am only learning in my spare time and just try to get thgrough what i can when i can

so how can i attach my custom toolbar to the file to send to you?

thanks

lucas
09-04-2007, 06:53 AM
so how can i attach my custom toolbar to the file to send to you?

see post #11 and look at question # 2 in that post.

fumei
09-04-2007, 09:14 AM
Oh please do misinterpret what I am saying. I certainly do not think you are trying to waste my time.

I will say it again. You need to start to understand how Word works, and you must actually read the posts that people post. The fact that you have to even ask:
so how can i attach my custom toolbar to the file to send to you? shows that you do not understand some basics of Word.

What you posted is template (.dot) file. Why do you not create the toolbar in it? That is the point - which has been stated to you - of templates. It has also been clearly stated that Word will put code/toolbars etc etc. into normal.dot by default. So, YOU have to explicitly put it/them into your template. You.

i thought that the toolbar was saved to that file which was a template and not a .doc file???You think that because you do not understand the basics of how Word, and templates, work.

There is nothing inherently wrong with that. We ALL started not knowing. We learn by study and asking questions.

northernstar
09-04-2007, 02:35 PM
thanks for all your help, i think i have sorted the template problem and i have it working on two pcs, just need to put it on the rest

thanks again

Anne Troy
09-04-2007, 07:39 PM
Northernstar: Here's a few articles that may help you, should you choose to take the time to read them. I've placed them in order of what I believe to be their importance in understanding Word...
1. http://www.officearticles.com/word/about_normal_dot_in_microsoft_word.htm

2. http://www.officearticles.com/word/template_tips_for_microsoft_word.htm

3. http://www.officearticles.com/word/what_to_do_with_macro_code_in_microsoft_word.htm

northernstar
09-04-2007, 11:02 PM
thank you very much.....i will have a look at them and hopefully they will help me no end

thanks again

fumei
09-05-2007, 01:01 PM
Anne, you are such a sweetie.

northernstar
09-05-2007, 10:57 PM
please find attached a copy of the template which appears to be working on my network now, thanks for asll your help and any comments/advice would be appreciated

thanks again!

lucas
09-06-2007, 08:53 AM
Now you're headed in the right direction...
The code was password protected so I couldn't look at it but that doesn't matter. You have made the basic error of using the normal.dot instead of renaming it to some other name and put it in the startup folder. If it is named normal it will conflict with other users on the network who already have a normal.dot.

northernstar
09-06-2007, 09:30 AM
thanks for that

the password is 2729

it is saved in a different location on the network

i will rename it now

thanks

northernstar
09-06-2007, 09:37 AM
hi

now i am heading in the right direction, what if i want to make up more templates which go off say log in name

or how do i determine which template is to be used when?

thanks

lucas
09-06-2007, 09:40 AM
Sounds like you got things hashed out. If each user points their startup directory at the directory on the network where your file is located you will be in business.

You can change the file and all users will see the changes when they run Word.

lucas
09-06-2007, 09:45 AM
how do i determine which template is to be used when?

If they are in the shared network directory and the users have pointed to that directory for startup then all templates in that directory will run when they start Word.

I should qualify that by saying that the code will not actually run but will be available to be run by all.

Code that gets username/login name info will still work and will reflect the user who runs the code at that moment in time.

northernstar
09-06-2007, 11:15 AM
so correct me if i am wrong here

if i make up 10 templates all different, then when word is opened how will it know which one to open/use?

northernstar
09-06-2007, 11:17 AM
not sure why i would want to make up 10 different templates but i am trying to understand how templates work

normal.dot is the general one which is used even if other templates are available, how does word know when to change which template to use, can or is it done via code?

thanks

northernstar
09-06-2007, 11:19 AM
did you get a chance to look at my code?

would appreciate any comments / advice

looking at creating arrays at the moment to condense all the procedures into one

lucas
09-06-2007, 11:46 AM
so correct me if i am wrong here

if i make up 10 templates all different, then when word is opened how will it know which one to open/use?
These are .dot files but they are not being used as templates. They are being used to store toolbars and code. You should only have one of them and it should contain all of your toolbars and code that you wish to make available.

Template for file creation or cloning go in your templates directory and are available under file-new....they are two completely different things.

You can have code in your global that creates a new document from any of your template files....

Normal is the template that word uses as a default to create a new blank document...you can change that if you wanted to but why would you.

northernstar
09-06-2007, 12:24 PM
ok then, if i dont want all the code and toolbars available to all users then

and how do i get word to select the correct global template?

did you look at my code in the file i sent you?

fumei
09-06-2007, 12:29 PM
If you have 10 different templates, one would assume that they are used to create 10 different types of documents. NOT different documents with different data, but 10 different kinds of documents.

The real question is: HOW are the users deciding which document to create in the first place?

Document templates and global templates are both .dot files.

Document templates are used to create documents. Documents made from templates are clones. They are EXACTLY like the .dot file. The intention is to create a new document EXACTLY like the template, then the user can input data, or text...something...that will make that particular document unique. The intention of a document template is to maintain a common look and structure.

Say a Letter.Dot - a template for creating letters. It can have headers and footers, or logos, or whatever, plus Styles. ALL letters created from that template will have these common elements. The text content will change of course for each letter, but the look and structure will be the same for them all.

Global templates are also .dot files. However, their purpose is quite different. They are intended to be code containers. They are intended to be used for all documents, regardless of document template used to create those documents.

Globals templates can be used for toolbars or other user interface structures.

Document templates can also contain code (and often do), and toolbars. However, these will only be available for documents created from THAT template.

Do you want "stuff" - code, toolbars etc. - available for ALL documents? Use a global template.

Do you want "stuff" - code, toolbars etc. - available for just the certain documents? Use a document template.

Technically speaking, document templates do NOT have to be in the template directories recognized by Word. Calling a .dot file will create a new document from that template, regardless of how it is called. The template directories recognized by Word simply make them visible with File > New.

For example: a global template (in Startup so it is loaded automatically) may have a button on a toolbar. That button can call a document template from anywhere. Or that global may have a menu dropdown which lists a number of templates. Letter, Finacial report, Staffing...whatever. The template file that is called by selecting one of those does not, technically, have to be in one of the Word template directories.

I would agree with Steve that generally speaking, you should have one, or two, globals. I have ONE that is in Startup, so it loads automatically. However, it has buttons that load (and unload) other globals. They are NOT in Startup. This way I can load them as temporary globals.

Going back to the question:

"if i make up 10 templates all different, then when word is opened how will it know which one to open/use?"

How do you WANT to determine which to use? What criteria, what logic, is used to decide which to use? Once you know that, actually calling the decided upon template is easy.

"normal.dot is the general one which is used even if other templates are available, how does word know when to change which template to use, can or is it done via code?"

This is not correct. Normal.dot is not used "even if" other templates are available.

ALL documents have an attached template.

If a document is not cloned from an explicit template (using File > New by menus; or created by code), then Word attaches normal.dot.

ALL documents have an attached template. So if you do not explicitly tell Word - use THAT template - then Word will use the default template...normal.dot.

Documents not created from an explicit template (ie. the attached template is normal.dot) may have a template attached to it after the fact. That is, an existing document can have a different template attached to it. Attaching a different template to an existing document supercedes the previous template. The previous template is no longer attached. Any code, or toolbars etc., that were in that previous template will no longer be available.

"what if i want to make up more templates which go off say log in name

or how do i determine which template is to be used when?"

This is strictly, and only, a matter of logic. That logic has to be determined. These are decisions. Make the decisions. Writing the actual code for it is small stuff.

I can not stress this enough. Writing code is (contrary to what many people think) the minor part of creating VBA applications. THINKING is the major part. VBA, like all programming languages, is based on the use of logic. It does not do ANY thinking for you. It follows rules. It does exactly what it is told. No more. No less.

99.9% of the time if something is not going the way you want it to, it is because you have not told it the right thing.

There is of course that wee bit that can only be described as the ghost in the machine.

The problem is...unfortunately...the object model built may be weird. Word is a good example of that. It has some....odd...aspects. Some very infuriating aspects. It has aspects that are not intuitive at all. Some are decidedly counter-intuitive. They appear to make no sense at all.

Nevertheless, they MUST follow logic. Skewed, twisted and even stupid logic at times, but logic none the less.

So regarding whether to use template C, instead of template G...that decision is up to the coder (assuming it is being done with code). Telling Word to actually DO that...minor stuff.

lucas
09-06-2007, 12:54 PM
99.9% of the time if something is not going the way you want it to, it is because you have not told it the right thing.

I read the acronym that covers this in our forum the other day. Don't remember who shared it.

It's called a picnic error. Problem In Chair Not In Computer



There is of course that wee bit that can only be described as the ghost in the machine.

The problem is...unfortunately...the object model built may be weird. Word is a good example of that. It has some....odd...aspects. Some very infuriating aspects. It has aspects that are not intuitive at all. Some are decidedly counter-intuitive. They appear to make no sense at all.

Nevertheless, they MUST follow logic. Skewed, twisted and even stupid logic at times, but logic none the less.

Word is different.

northernstar
09-06-2007, 01:01 PM
ok thanks for that fumei

i am still looking through your message regarding the arrays and i am still trying to understand it fully and hoping to have a sample for you to look at soon....but i am puzzled by the sample code you wrote

for var = 0 to ubound(MyList)
Dropdown1.AddItem MyList(var)
Next

what is var? is it a variable?

thanks for your help

lucas
09-06-2007, 01:03 PM
You have a wealth of information here now. Thanks for that Gerry. I am going to bookmark this thread and use it for a reference.

Yes, I looked at your code. You should put Option Explicit at the very top line of your module. Always use Option Explicit and you will know immediatly if you have errors....

What exactly do you want to know about your code?

northernstar
09-06-2007, 02:42 PM
Sub Proforma()
' sets up the constant path
Const Proformas As String = "x:\Mechanical\Master Blanks\Master PDF\"

'sets up the top folders
Dim Folders As Integer
Folders = Array("Ukas", "Standard", "Master Specified")
'sets up the subfolders
Dim Ukas As Integer
Ukas = Array("Micrometers", "Verniers", "Levels", "Force")

Dim Standard As Integer
Standard = Array("General", "Torque")

Dim MasterSpecified()
MasterSpecified = Array("General", "Micrometer", "Vernier")

For Folders = 0 To UBound(Ukas)
Dropdown1.DropDown.AddItem Ukas(Folders)
Next

End Sub

this is what i have done so far but having trouble with the dropdwon part??

northernstar
09-06-2007, 02:43 PM
not sure if i should have used integer?

lucas
09-06-2007, 02:53 PM
dim them all as variant

northernstar
09-06-2007, 03:02 PM
still cant seem to get the dropdown to work?

Dim DropDown1 As Variant

For Folders = 0 To UBound(Ukas)
DropDown1.AddItem Ukas(Folders)
Next

lucas
09-06-2007, 03:11 PM
don't dim the dropdown...dim the arrays as variant
specifically in your last post....Ukas and Folders

fumei
09-06-2007, 03:57 PM
northernstar, I can admire you wanting to create relatively sophisticated VBA applications. However, the truth is...you are way over your head. You need to start learning some basics. You need to learn, and understand some concepts.

Dim Standard As Integer
Standard = Array("General", "Torque")

WHY did you do that? WHERE did you get that from?

To everyone else: northernstar PM'd me regarding arrays, and I responded with a very long reply, with examples. That is where he is getting some of the stuff above.

HOWEVER, I most certainly did NOT give any example like

Dim Standard As Integer
Standard = Array("General", "Torque")

The second line is setting an array. The first line is declaring a number.

Sheeeesh.

As Steve mentions, for goodness sake, use Option Explicit!!!! This has been mentioned to you before. The fact that you have the above code at all shows that you are not listening. If you had Option Explicit you would not being able to run that code at all...because it is WRONG.

Where on earth did you get the idea of declaring it as an Integer????

Sigh, I am sorry, but I am finding this too frustrating for the time being. Sincerely, all the best. Again, I really do respect that you are trying to do serious coding. I am just not attached to writing long, detailed explanations when they do not seem to actually help. I think you have received more than enough assistance from me, for now.