Is it possible to have a macro run in Visual Basic Editor?

M

Mike

I've written a number of macros for my group, and I'm trying to
implement a distribution process that is as simple as possible. I'm on
a team of 4 and the other 3 members are not as skilled with Word as I
am, so the easier I make it for everyone, the more likely they are to
actually use these macros I've created. Now, I must inform you that I
am aware that I could create a template and share that, but I had some
problems actually trying to get that to work, so I have no desire to go
that route.

The process that I have in place right now is as follows:

1) I copy all of the code in Visual Basic Editor and paste into a new
document, which is located on a shared drive.
2) My team members all go in and copy everything in the document, open
up VBE and paste everything into their own template (Normal.New
Macros).

The toolbar macros that were already there remain, but the keyboard
shortcuts are wiped clean when the entire code is pasted into VBE.
That initially was a big problem, but I created a macro that will
assign keyboard shortcuts to macros. A sample of that code is as
follows:

KeyBindings.Add KeyCode:=BuildKeyCode(wdKey1, wdKeyAlt),
KeyCategory:=wdKeyCategoryMacro, Command:="Zoom_100"


So here is my goal for making the distribution process easier. I have
decided to create a Word document with 2 big buttons - 1 to update
all the code, and 1 to run the macro that assigns the keyboard
shortcuts. I will send this Word document in an email every time I
update the code and my team members will be able to update their macros
in a matter of seconds.

The second button is no problem, as it's just calling another macro.
The first macro is giving me some issues, though. I've got this much
so far for when the first button is pushed:

Private Sub copymacros_Click()
ChangeFileOpenDirectory "N:\Formsteam\Mike's Macros\"
Documents.Open FileName:="Macros.doc"
Selection.WholeStory
Selection.Copy
ActiveDocument.Close
ShowVisualBasicEditor = True

Selection.WholeStory
Selection.Paste
MsgBox strText & "Your Macros have been updated. Thank you.", 64
End Sub

My problem occurs in the 2 lines "Selection.WholeStory" and
"Selection.Paste" because, as it runs on the Word document, and not
the code in VBE.

Is there anything else I can do to get this to work? Obviously, if
this was running form another macro program, this would not be an issue.
 
H

Helmut Weber

Hi Mike,

use a log-on script or simple bat-file
in the startup or autostart folder (depends on the version)
for copying your templates from the server
to the startup-folders of the workstations.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

Mike

Helmut said:
Hi Mike,

use a log-on script or simple bat-file
in the startup or autostart folder (depends on the version)
for copying your templates from the server
to the startup-folders of the workstations.

I'm sorry, Helmut, but I'm not sure I understand what you mean.
 
H

Helmut Weber

Hi Mike,

I meant, as sharing templates may cause problems,
don't use shared templates,
but give each user a copy of a master template.

The master template (dot) could reside on a shared drive,
where it is always accessible to you for maintanance.

After log-on of a user,
copy the master template from the shared drive
to the startup-folder of Word on the workstations.

This could be done by a bat-file, e.g.
....\programs\startup\getdots.bat

Could it be, that this basic approach isn't known anymore?

If so, ask again.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
S

Shauna Kelly

Hi Mike

If I may guess at what Helmut had in mind (and which I, too, would
recommend):

1. Create a template (.dot) file.
2. Store your macro code there.
3. Store your toolbars there.
4. Save it in your Word Startup folder (the one listed at Tools > Options >
File Locations > startup).
5. Close Word.
6. Test to see that it works on your machine.

You may need to clean out any extraneous code in your normal.dot.

When you're happy with it, you have two options.

Option 1 (the good way, which Helmut recommends, and which is known to work)
1. Copy the template file to a server location.
2. Get your IT people involved to write a script or a simple batch file that
copies the file from the server location to each individual user's Word
Startup folder. (This requires either (a) a program that runs to determine
where each user's Word Startup folder is or (b) that each person's Word
startup folder is in the same location.)

OR

Option 2 (the slow way, that only works with human intervention, and only
for a very small number of users, and only for people using desktops or
laptops, but not for remote users)
1. Email the file to your colleagues
2. Tell them to close Word and then save the file into their Word Startup
folder (the one listed on the individual's machine at Tools > Options > File
Locations > startup).


Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
C

Charles Kenyon

Do not - repeat - do not - be messing with other user's normal.dot. You
don't want to put macros you've spent time on in the NewMacros module. That
is the scratch module. You may well be wiping out your user's work as well.
Instead, use a global template that holds them. This goes in each user's
Word startup folder. You can put it on the network and have the login script
for each user copy (update) it to a local Word startup folder.

See http://addbalance.com/word/movetotemplate.htm for step-by-step
instructions on moving / sharing / copying / backing-up customizations
including AutoText, AutoCorrect, keyboard assignments, toolbars, macros,
etc.
--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide




--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
S

Steve Yandl

Mike,

Just to add to Shauna's comments above, here is a sample script you could
use to update each user's template to be in sync with the master template
you would maintain on the server. You would take what I have between the
dotted lines below and create a new text file. Edit the line that reads:

strMasterTemplate = "\\atl-fs-01\public\master.dot"

so that it reflects the correct path to the location on the server where you
store "master.dot" Save the new text file with a vbs extension. On each
user's PC, place a copy of the script in a convenient folder, say
"C:\scripts\chkTemplate.vbs". Go to the folder, C:\Documents and
Settings\{user ID}\Start Menu\Programs\Startup and create a new shortcut
with target:

cscript.exe "C:\scripts\chkTemplate.vbs"

Now, whenvever the user starts up, the script runs. It identifies the local
location for Word's startup folder, looks for master.dot in that folder and
copies it from the server if it isn't found. If master.dot is found
locally, the script checks if the master.dot file on the server has been
modified more recently than the local file and copies the server version to
the local machine if that is the case.

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Const wdDoNotSaveChanges = 0
Const OverwriteExisting = TRUE

strMasterTemplate = "\\atl-fs-01\public\master.dot"

Set objWord = CreateObject("Word.Application")

strWdStartPath = objWord.Application.StartUpPath

objWord.Quit(wdDoNotSaveChanges)

Set objFSO = CreateObject("Scripting.FileSystemObject")

If Not objFSO.FileExists(strWdStartPath & "\master.dot") Then
objFSO.CopyFile objServerFile.Path, strWdStartPath & "\"
End If

Set objLocalFile = objFSO.GetFile(strWdStartPath & "\master.dot")
dtmLocalDate = objLocalFile.DateLastModified

Set objServerFile = objFSO.GetFile(strMasterTemplate)
dtmServerDate = objServerFile.DateLastModified

If dtmLocalDate < dtmServerDate Then
objFSO.CopyFile objServerFile.Path, objLocalFile.Path, OverwriteExisting
End If
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Steve
 
M

Mike

Helmut, Shauna, Charles, and Steve,

Please accept my apologies for my ignorance. I was aware that a
template could be created, but my first attempt at creating one a
couple months back resulted in failure, and because I am so stubborn, I
was convinced that I could figure out another route (as indicated in my
first post).

Because all of you were adamant about me creating a template to share
my macros, I finally realized that I needed to take another shot at it.
This time, I was successful! Looking back, I am not exactly sure what
the problem was, because now it seems so easy.

As far as the suggestion of a batch file, I appreciate the assistance.
Because there are only 3 other people I need to distribute the template
to, I'm going to stick to the email route for now. In a larger
environment, I can see where that would be absolutely necessary,
though. My reasoning is that if I wanted to have an update in the
middle of the day, I would need everyone to restart their computer for
the changes to take effect. It is possible that both methods may be
better, so I may have to rethink that in the future.

I also need to apologize for taking so long to respond. My company
decided to implement a plethora of new internet blockages - one of
which includes Google groups. I had to jump through a few hoops to
have this section unblocked.

I do have one issue with the custom template, concerning the toolbar
that I've created. I've been making little changes to it here and
there by opening the template directly from my desktop and then putting
it back in the startup folder to make sure it works once I am done.
The issue I have is if I open more than one document, only the first
open document will have the most recent toolbar. The second document
- and every document thereafter - will have an older version of the
toolbar I created (albeit the same old version). I have Word set to
open a new window for every document, by the way. I checked my normal
template and there is no toolbar in there whatsoever, so where would
this old toolbar be stored? Is it just a glitch in Word? By the way,
I have not tested to see if this occurs on anyone else's computer.

Thank you all again,

- Mike
 
C

Charles Kenyon

Did you close and reopen Word?

The way I modify a global template, that isn't being used by someone else,
is to simply open it and make the changes, then save them.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide




--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
M

Mike

Yes, I've closed and reopened Word many, many times and every time I
get the same result. I really don't understand it. The first instance
is always perfect and the second, third, fourth, etc. always has an
older version of the toolbar. I've gone into customizations and it is
the same exact toolbar, but it's not behaving properly.

- Mike
 
M

Mike

Just a quick update -

I distributed the the updated template and the error of the wrong
toolbar appearing does not occur on other computers.
 
N

njmike

My last update -

I found the problem on my end was easily fixed by deleting the Normal
file and letting Word rebuild it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top