Run a .BAS file at startup

M

matth0101

I have Office 2003. Within Word I created a Macro that changes 1 setting
within Word. I need this Macro to run when Word starts.

I Exported my Macro into a .BAS file. I have placed this .BAS file in this
location:
C:\Documents and Settings\%user%\Application Data\Microsoft\Templates

But when I start Word it does NOT run this Macro.

I have placed the .BAS file here:
C:\Documents and Settings\%user%\Application Data\Microsoft\Word\STARTUP

But when I start Word it does NOT run this Macro.

How do I make Word run any .BAS file at startup?
 
G

Graham Mayor

Import the macro BAS file into a template - save the template in the startup
folder.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jay Freedman

If the setting that's changed by the macro doesn't require any document to
be open at the time, then the macro should be named AutoExec() and stored in
a template in the Startup folder. See
http://www.word.mvps.org/FAQs/MacrosVBA/ApplicationEvents.htm.

If the setting must be applied after a document is open, then the macro must
be imported into Normal.dot and named either AutoNew() or Document_New().
See http://www.word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm (and
specifically the part where it says that an AutoNew macro in a global
template is ignored).

In any event, a .BAS file cannot be executed, whether in the Startup folder
or anywhere else. It's just a text file representation of a macro. It must
be imported to some template in order to run.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
M

matth0101

Thanks. How do I import the .BAS file into a template? I have gone into
Word 2003 and picked Tools\Templates & AddIns but I don't see any Import
command.

When I try to add my BAS file it tells me this is not supported etc....
 
J

Jay Freedman

You exported it by right-clicking a module in the VBA editor and choosing
Export To File. The Import command is also on that right-click menu --
right-click the icon for the template where you want it imported, and choose
Import From File, and use the dialog to locate the .BAS file.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
M

matth0101

Thanks but I think I was unclear. Yes, I have exported my macro. I now
have a file called TurnOffBalloon.bas. On hundreds of machines I need this
..BAS file to run when Word starts. So it has to be automated. Also, I don't
want to call my file AutoExec since users may have already created their own
AutoExec macro's and I don't want to overwrite anything.

So back to what Graham said....how do I turn t his .BAS file into a Template
file?
 
M

matth0101

Any info on how this is done? I have looked in all parts of Word 2003 and
don't see where you can import or convret a BAS file into a template.
 
J

Jay Freedman

Basically (pun intended) there was no need to export the macro to a .BAS
file. As I said before, a .BAS file is NOT executable in any way -- its only
purpose is to be imported to some other template. It would have been simpler
just to copy/paste the code of the macro into a new module an otherwise
empty template, and then distribute that template.

Further, the only way to get a macro to run automatically (as opposed to
merely being available) at Word's startup is to name it AutoExec and to
store it in either Normal.dot or an add-in template (or call the macro
something else and then put a call to it into an AutoExec macro).

Well, there is one way that works without naming the macro AutoExec, but
it's just as difficult to deal with and only handles some of the problem:
Replace the desktop icon for Word with one in which the command line has a
/m switch followed by the name of the macro
(http://support.microsoft.com/?kbid=210565). But the macro still won't run
if someone starts Word by double-clicking a document, or by using the Start
menu.
 
S

Suzanne S. Barnhill

You have misunderstood Jay. Naming your macro AutoExec won't interfere with
the AutoExec macro in Normal.dot because yours will be in a separate
template in the Word Startup folder.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
M

matth0101

I'm sorry if this is easy and I am just not getting it.

When you create a new template file how do you make it execute your code
(that you cut and pasted from your .bas file)? When I created my
AutoExec.dot file I tried to copy the code from my .bas file into it but when
I start Word it does not exceute my macro.
 
M

matth0101

Here is what I have done.

In Word 2003 I started up the program. I had a blank document. I picked
Save As and chose the Document Template (dot) type of file.
I gave this .dot file a name and picked Save.
Then, while still in this .dot file I created my Macro and once completed I
picked Save again.
This did save my .dot file in the same folder location as the Normal.dot file.

This does not work either. When I start up Word it does not execute my
custom template file.
 
S

Suzanne S. Barnhill

As you have discovered, the Templates folder (where Normal.dot is stored)
is not the correct location; you load a template as an add-in by placing it
in Word's Startup folder.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
G

Gordon Bentley-Mix on news.microsoft.com

Amen!
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 

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