PDA

View Full Version : Distributing a VB module



timetunnel
01-13-2007, 04:15 PM
Hi all.

I'm new to this forum and not skilled. I haven't done any programming in years, but I somehow managed to hack together a module ( I guess it's considered a module with a macro??? I'm an idiot!) to pull 2 previously filled in WORD form files from a certain directory and insert them into a 3rd blank WORD doc (which I call the merge doc) that has been properly formatted to accept the inserts without splattering them. I somehow managed to create a custom button that launches this VBA module/ macro and I'd like to be able to get this module and the associated button onto other users PC's without recreating the code. This module (or whatever it is called) is associated with my normal.dot, but beyond that I'm lost.
In fact it was dumb luck that I managed to get any of what I mentioned above to happen! I just kept on hacking and finally at 2:00AM one morning it worked. Maybe you know how that goes...

This isn't all I want to do with this project, ( for instance I want to be able to AUTOMATE saving the 2 filled in form files as new docs without messing up the original blank versions and want this to be as easy for the users as possible. Preferably by filling in save info in a pop-up or some such thing and would also like to find some way to handle folder management in an automated fashion), but for now I'd just like to get that code onto other PC's.

I know this must sound like a lot of stuff, but any help with any piece of it would be extremely appreciated.

Regards to all!

Ken Puls
01-14-2007, 11:46 AM
I'm not a wordie, but it seems to me that you're going to want to store this in a global? template of some kind to distribute it. I'll see if I can call someone for you who has some experience with Word.

:)

Bob Phillips
01-14-2007, 12:21 PM
This definitely sounds as though you want to save these files as template files (.dot extension). If you make these available to your colleagues, either give them a copy, or store on a network drive, they can open them as templates, and save them as pukka Word documents.

Ken Puls
01-14-2007, 12:29 PM
pukka?

mdmackillop
01-14-2007, 12:39 PM
It is best practice not to store your macros in Normal as this is often corrupted and is the first file removed in solving Word problems. The solution is to copy your macros into new template documents as suggested by XLD. If you want these macros to be available at all times, copy the template(s) into your StartUp folder. To edit macros, it is neccesary to open the template containing them. They are not directly accessible from the VBE. In my case, macros are stored im Macros.Dot (see below)

If your macros relate to only one document type, then save them in that document template.

Bob Phillips
01-14-2007, 02:06 PM
pukka?

I feel that have been here before?

Pukka is a word that has been absorded into English from our Indian experience. It means real, or in strict definition, genuine, or first class. It comes from the Hindu word pakka, meaning cooked or ripe.

timetunnel
01-14-2007, 04:14 PM
To everyone who replied:
Thanks a ton!!!! I've got a lot to learn!
I can see the logic in storing the macro in a template. Now all I have to do is figure out how to do that. I assume it's as simple as moving it around. However, now that I have it in Normal.dot, will I simply be able to relocate it into a new template or will have to cut it and paste it ? I don't quite get that piece yet.

I can just imagine how utterly stupid this must sound and I'm really not that dumb! I promise I'm not - or AM I???

mdmackillop
01-14-2007, 04:39 PM
Simplest way, make a copy of Normal.dot with a new name. Clear out the macros etc. you don't want in your new macro for distribution.

Ken Puls
01-14-2007, 04:41 PM
I feel that have been here before?

Pukka is a word that has been absorded into English from our Indian experience. It means real, or in strict definition, genuine, or first class. It comes from the Hindu word pakka, meaning cooked or ripe.

Don't recall the explanation before, so thanks! :)

Bob Phillips
01-14-2007, 04:56 PM
Don't recall the explanation before, so thanks! :)

Not necessarily here, but I am sure it was in the last month or so.

Bob Phillips
01-14-2007, 04:58 PM
To everyone who replied:
Thanks a ton!!!! I've got a lot to learn!
I can see the logic in storing the macro in a template. Now all I have to do is figure out how to do that. I assume it's as simple as moving it around. However, now that I have it in Normal.dot, will I simply be able to relocate it into a new template or will have to cut it and paste it ? I don't quite get that piece yet.

I can just imagine how utterly stupid this must sound and I'm really not that dumb! I promise I'm not - or AM I???
Just save the wor document as a template, select it from the drop-down when you save it.

Not a good idea to save it as Normal.dot, because you might overwrite other people's customisations when you distribute it.

fumei
01-15-2007, 04:49 AM
The easiest way to move modules from Normal.dot to an new template is in the VBE itself.

You can, as suggested make a copy of Normal.dot, but it is not needed. Normal.dot can hold a lot of other stuff that you may not (or may) need.

If you just want to copy a module, simply have both files open, and drag and drop the modules within the VBE. Simply drag your module from Normal, and drop it onto the Project of the file you want to copy it to.

If you have created a button to fire the procedure, then to get that button to the other PC, you either have to have the new template (with the copied over module) cloning a new document, OR load that template as global. That is, as Malcolm mentions, in the Startup folder.

NOTE: you can drag and drop modules. To copy procedures you have to copy and paste.

The other way to copy modules is use the Organizer. However, I find it just as easy (or easier) to drag and drop in the VBE.

Bob Phillips
01-15-2007, 06:18 AM
He wants it for users, so it is probable that he wants to make it as simple as possible for them.

fumei
01-15-2007, 10:44 AM
Users? That was not for the users. It was for the OP to move the code from normal.dot to some other file. There was no mention of the users moving code modules.

Bob Phillips
01-15-2007, 11:02 AM
I am referring to what the Op wants to do.

fumei
01-15-2007, 03:19 PM
From the OP:
I'd like to be able to get this module and the associated button onto other users PC's without recreating the code.The discussion was on how to do that. It was mentioned that it is better to have this NOT in normal.dot.

The discussion further was about getting the code in a distributable form, with the suggestion it be done as a global template placed into Startup.

So far, there is no serious mention at all about what the users will, or will not do.

In fact, the OP is quite unclear as to what the users will, or will not, do; and is unclear IMO, as to what is actually to happen.

On one hand - A):
pull 2 previously filled in WORD form files from a certain directory and insert them into a 3rd blank WORD doc

On the other hand B):
I want to be able to AUTOMATE saving the 2 filled in form files as new docs without messing up the original blank versions

A - two already filled in docs (originals), going into Doc 3

B - two blank docs (originals) being filled in.

Until that is cleared up I am not sure we can make much comment about user actions.

However, timetunnel, in that vein, you may want to consider the use of a template (not just as a code holder). perhaps if you described the steps you wish to take in more detail.

timetunnel
01-16-2007, 10:09 AM
To everyone:
Thanks for responding. I think I'm there, but there may be a missing piece.

I've now got a doc with a button that fires the proc. It prompts the user for the names of the 2 doc files that are to be merged (inserted in to the 3rd doc) and also prompts for the save-as name for the 3rd (merge target) doc. This all works perfectly.

Let me clarify what I'm actually doing with this thing: The scenario is this: There are 2 "work groups" who will use these. The docs have headings or "boiler plate" if you will that I don't want blown away and thus is protected. Then below each boiler plate heading (topic) area, there are fields into which they can key info relating to that heading or topic.

Doc 1 is common to both groups, contains info common to both and will be edited by both. Doc 2 will actually be used by both groups too, but will contain info unique to each.

Logistically, it can be viewed that doc 2 is really 2 unique docs from the perspective of the groups, but it wasn't really necessary to create a 3rd doc as a lot of commonality exists.

The thing is that after the initial usage of the new docs, both work groups will work off of previously edited versions of the 2 docs, (tweaking them as is appropriate day-by-day and saving them a new docs). Thus, they will probably never open a "blank" version of the document again, but will open one of the previously filled in ones, doctor it up and save it as a new doc.

So the objective of my project is to allow each group to fill in a copy of the 2 docs, open my "merge control" doc, fire the proc which prompts for the 2 docs they want to merge and the name of the new merge doc they'll create!

Now all I'm wondering is this: If I place the Word doc with the button that fires the proc into a network directory for sharing, will everyone with rights to that directory have the ability to fire that proc in the doc, or will something more have to be done? Is that proc unique to my copy of Word and does the proc have to be copied onto every users PC or is it embeded in the doc and thus will fire for anyone opening the doc?

I'm thinking that the reason it works for me is that my normal.dot knows the proc exists. As everyone has pointed out, I really don't want to create a dependency on normal.dot and then have to figure out how to manage that nightmare!

One more thing I just thought of after re-reading replies: This whole thing is in 1 subroutine. I don't know if it's a project, a module or what it is from the standpoint of Word.
I assume it's always a project and that within projects modules exist. Again, I also assume (or at least hoping) that if I have a Word doc with a button that fires this thing, that when I move the doc to a shared directory the code will be there.

It was really easy to figure out how to tie the button to my code because the module (or whatever it is known as) showed up in a list when I created the button. But, when I look at the project structure in VBA, I can't seem to get anything to happen when I try to expand the folders.

I'd read VBA 101 if I knew where to find the book!

Man it bytes getting old! Or should I say getting ole? I'm an idiot wrapped in a moron!

Regards EVERYONE!

mdmackillop
01-16-2007, 10:16 AM
Can you post a copy of your template containing your code? Use Manage Attachments in the Go Advanced section. Clear any sensitive info from your template first.

fumei
01-16-2007, 02:58 PM
1. As has been stated, if you have a global template in Startup for everyone, then the procedures in that are available for everyone.

2. I would repeat my suggestion that this is a job for templates.

timetunnel
01-17-2007, 09:59 AM
Hi again:
So what I'm hearing is that a template behaves differently than a standard doc. I originally created the pieces of my project as templates and then just started saving them as docs. Everything seemed to behave the same regardless. So is the difference "under the covers" in terms of how it links the code?

Also I'm not quite getting the term "global" template. Is this a special option that allows a template to behave differently? My plan was to have these templates live on a network drive where everyone could get to them. Will these actually have to be copied to each individual PC due to the VBA code I'm using?

I'll post a copy of my code as soon as I can. It's at work and I'll have to email it to myself and deal with it from home as we're not allowed to mess around on the Internet.

Just thought of one more thing: Last night I was working on this and found out that the module was failing because it couldn't find one of the doc files that I'm fetching with a name passed via an input box. When I played with it I discovered that if I pass the path & the file name in the input box it works fine. This is strange because I have a CD statement in my code, which worked fine the day before! Is this code rot?

Anyway, thanks everyone! I'm really enjoying this collaboration! Well, actually it's more me being schooled than anything else cause I don't have much to give back right now! But, it's sure cool!

fumei
01-17-2007, 10:45 AM
Hmmmm.

Global templates are .DOT files that are used to store procedures (code). That is their main purpose.

ANY .dot file can be loaded as a global template.

They can be either loaded automatically (by placing the .dot file in a Startup folder), or loaded dynamically. They can be loaded dynamically either by code, or manually using Tools > Templates and Addins.

Global templates (when loaded) are NOT open. Word parses the code procedures and creates pointers to them. You can open a loaded global template and change code and it is immediately available.

Templates (not used as global) ARE different from documents. Their purposes are to create documents that are clones (exact copies) of them. The original (the .DOT template file) is NOT opened, and is NOT changed when a new document is cloned from it.

Let's review. For the moment, forget about what the users do. If you want a button to show up for all users, put it in a global template and make sure it is in each user Startup.

Boilerplate strucure should be done as a templates.

will open one of the previously filled in ones, doctor it up and save it as a new doc.
This can of course be done like that, but really, the chance of errors points to using a template. Generally speaking, it is not a good idea to open a document to change something into another document. Especially if there is common structure - boilerplate.

So....

Have a global template with a button. The global is correctly placed in Startup, and the only thing in it is the button and some code to clone a document template.

THOSE template files can be on a server.

The button is clicked, and the server located template file clones itself (with the standard boiler plate stuff) as a new document for the user.

If I place the Word doc with the button that fires the proc into a network directory for sharing, will everyone with rights to that directory have the ability to fire that proc in the doc, or will something more have to be done?If a procedure exists in a document, then it exists in the document. if the user can open the file, then the procedure is available to them.

timetunnel
01-17-2007, 11:53 PM
Thanks Gerry!
Great explanation! Perfect in fact!

I'm off and running - to somewhere...

I'll post more as soon as I can. I'm getting slammed at work right now and I'm new on this gig, just came out of retirement after about 3 1/2 years off of the wheel and I'm getting worn out working way too many hours.

Now I remember why I got out of IT, but can't figure how I got back in it!

Just as a side note, I mentioned in a previous post that my code was having trouble opening the file names passed in through my input box unless I added a path (even though I had a CD statement in my code. It was because I had the directory open in the background and VBA didn't like it.

Imagine that.

Regards!