Changing default window properties

D

Daiya Mitchell

Jacques and Scott, can you please both post the exact text of the macro that
does not run on the original new document, and exact OS and Office version
numbers (intel/ppc) for your setup, please?

Also, does the macro work partially, or fail completely?

Thanks, Daiya
 
S

scott.siegler

Daiya,

I run Office 2004 on Mac Powerbook (ppc) running OS 10.3.9.

I copied your macro exactly for both AutoOpen and AutoNew()

Sub AutoNew()

With ActiveWindow.View
.Type = wdNormalView
.Zoom.Percentage = 125
.TableGridlines = True
End With

With ActiveWindow
.Left = 6
.Top = 2
.Width = 479
.Height = 797
End With
End Sub
 
W

whitecloud1

Daiya said:
Hi Jacques,

I have no idea (and I'm very novice at macros, so with luck someone else
will chime in on this).

My AutoNew and AutoOpen macros are in Normal, so I haven't tested this. My
AutoExec (which sets some prefs on every launch) is in my Global Macros
template, though, so at least *some* auto macros can be global templates.

If you go into the Visual Basic Editor and select Help, there is a topic
"Auto Macros" that might offer some enlightenment (didn't for me, though).
John McGhie or some other macro expert hopefully will come along and explain
it.

Question--are you seeing the problem with the original new document that
Scott is seeing (where it doesn't run on the first one)? What does your
macro do? (or what is the code?)

Daiya

Hi, I'm joining this discussion. Following your postings, I managed to
set the default size and location for any new or opened document. i.e.
if I press Command+N it's perfect, or open any file. The only minor
problem now is when I Launch Word, then the default or Normal document
isn't aligned as in the macro settings. Even selecting new from Project
Gallery is perfect. Is there something I overlooked?
Best wishes,
JB

PS. Renaming macros can be done by copying and pasting the new name on
top of the old in the VB browser tab below. Trying to delete existing
name will cause shutdown of Word.
 
J

Jacques

I have copied the AutoOpen macro to the document template to which most
of my documents are attached, and it seems to work fine if I open one of
these documents.

It might also be worth creating the macro as ResizeWindow for manual
triggering when necessary.[/QUOTE]

There's no need: it seems you can run an Auto macro manually if you
want. I'll give it a keyboard shortcut.
Nothing you can do about that first new document, sorry. I wouldn't try to
stop Word creating it, but the macro to close it could work. You could try
to develop the habit of launching Word by double-clicking an existing doc
(then that blank doc doesn't come up).

But I want Word to adapt to my working practices, not the other way
round : )
Let us know what happens when you try it. :)

I get an error message: apparently Word can't do anything with the
active document because there isn't an active document yet. Figures.
Also, you might review the timing trick that John McGhie posted on this
thread, to give a delay before the macro runs.

Thanks, I will. I didn't understand it at first, but now I think I do.
Progress.

Jacques
 
J

Jacques

Sub AutoNew()
With ActiveWindow
.Left = 0
.Top = 0
.Width = 1443
.Height = 1028
End With
End Sub

OS 10.3.9
Office 2004 v. 11.2
original (ppc) Mac mini

Word appears to ignore the macro. There is no error message. The
document just opens at the wrong size.

Jacques
 
D

Daiya Mitchell

Hi JB,

Hi, I'm joining this discussion. Following your postings, I managed to
set the default size and location for any new or opened document. i.e.
if I press Command+N it's perfect, or open any file. The only minor
problem now is when I Launch Word, then the default or Normal document
isn't aligned as in the macro settings.

And can you also post the exact text of your macro and details of Office and
OS version numbers?
Even selecting new from Project
Gallery is perfect.

Ooh, interesting piece of new info. Thanks.
Is there something I overlooked?

Trying to figure that out now, info requested above helpful.
Best wishes,
JB

PS. Renaming macros can be done by copying and pasting the new name on
top of the old in the VB browser tab below. Trying to delete existing
name will cause shutdown of Word.

Oops. Thanks for the heads-up.
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Jacque:

What do YOU mean by "Global Template"? A global template MUST be in the
Word Startup folder: nowhere else. Distinguish this from an "Attached
Template" which can be anywhere.

Your compile error is because you have bad code in the named module. If
it's an ambiguous name, then it's in the same template.

You can have multiple macros named AutoOpen, provided you have only ONE in
each template :)

You can have (and sometimes, "should" have) more than one macro of the same
name in your current context. Your current context encompasses the
document, its attached template, its global template(s) and Normal template.

However, Word searches back down the hierarchy and executes only one copy:
the one closest in context to the active document. The hierarchy is:

1) Active Document
2) Attached Template
3) Global Templates
4) Normal Template

Cheers

Daiya, thank you: this works fine if you put the macro in the Normal
template. (It's like magic!) But when I put it in a global template of
my own, I get a "compile error" saying that the name AutoOpen is
"ambiguous".

This seemed to me to imply that Word didn't like the name AutoOpen
because I had already put an (identical) AutoOpen macro in the Normal
template. But that can't be it, because I tried renaming Normal and
restarting Word (so as to restore the original version of Normal without
the AutoOpen macro) and I still get a compile error from the AutoOpen
macro in my own global template -- except that it now says "Compile
error in hidden module: NewMacros".

So is it simply that you can't have a macro called AutoOpen (or
Auto****) in a global template other than Normal? If so, it's no big
deal: I'm just trying to get my head around this stuff.

Jacques
(using Word 2004)

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Business Analyst, Consultant
Technical Writer.
Sydney, Australia +61 (0) 4 1209 1410
 
P

Paul Berkowitz

The page on Auto Macros
is indeed helpful. The thing about an AutoOpen (or AutoClose) macro,
apparently, is that it only runs when you open (or close) --
(a) a document or template that contains the macro, or
(b) a document based on a template that contains the macro.
If neither of these is the case, it seems that the macro does not run --
even if it is in the Normal template, or another global template which
is currently loaded. Similarly, an AutoNew macro runs only when you
create a document *based on* a template which contains it -- not merely
because a global template containing it is currently loaded.


As best I recall, AutoNew does not work in Mac Word. Nor any of the other
Auto macros except for AutoOpen.

I have this installed in my Normal template:


Sub AutoOpen()
On Error Resume Next
ActiveWindow.View.Zoom.Percentage = 125
End Sub


It works to set the view to 125% on every new document I open - via cmd-N,
or any other way, including the blank new document that opens when launching
Word.

Yes, it must be in your Normal template, since that is what is used to make
new blank documents. As John says, you should not have macros with the same
name in more than one global template.

I have several other macros in a template I keep in the Startup folder
(which I keep in a safe place and alias to the correct location). I agree
with John that, in genera;, it's safer to keep templates in such a startup
template rather than Normal. But the new blank document that is created when
Word is launched opens _before_ any startup template. That's why it wasn't
working for you. This one needs to be in Normal and nowhere else.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
J

Jacques

Paul Berkowitz said:
As best I recall, AutoNew does not work in Mac Word. Nor any of the other
Auto macros except for AutoOpen.

AutoNew works fine for me in Word 2004, except that it doesn't work for
the document that Word creates on starting up. I haven't tried the
others.
 
J

Jacques

What do YOU mean by "Global Template"? A global template MUST be in the
Word Startup folder: nowhere else. Distinguish this from an "Attached
Template" which can be anywhere.

Hi John. The global template into which I tried to put an AutoOpen macro
was in fact in my Word Startup folder. But I'm surprised that you say a
global template MUST be there. In Tools>Templates and Add-ins there are
the options (a) to attach a document template, or (b) to add a global
template which is not already loaded. I just tried adding (as a global
template, not the document template) a template from outside the Startup
folder, and it seemed to work OK. Does Word use the term "global
template" in two different senses, sometimes including a template added
after start-up and sometimes not? Does a global template added after
start-up (if such a thing exists) behave differently from one loaded on
start-up?
Your compile error is because you have bad code in the named module. If
it's an ambiguous name, then it's in the same template.
You can have multiple macros named AutoOpen, provided you have only ONE in
each template :)

Sorry, I don't understand that. It was the same code that worked OK if
put in the Normal template. And it was the only macro I had put in the
global template. But I'm certainly confused about "macro projects",
"modules", "procedures" etc. The Missing Manual isn't much help on this,
but I've ordered a couple of Woody Leonhard's books on Winword 2000
which I hope will make things clearer.
 
J

John McGhie [MVP - Word and Word Macintosh]

What Paul says is correct: AutoNew won't work for the blank document
because it doesn't fire the DocumentNew event.

It does fire the AutoExec macro and that's the one to use for the blank
document.

I use a routine named "SetToolbars" that replaces the standard toolbars with
ones of my own invention. Here's how I call it:

Sub AutoExec()
Call SetToolbars
End Sub
Sub AutoOpen()
Call SetToolbars
End Sub
Sub AutoNew()
Call SetToolbars
End Sub
Sub AutoClose()
Call SetToolbars
End Sub
Sub AutoExit()
Call SetToolbars
End Sub


As you can see, that same macro is called on every document change event.
The reason is that it both reveals my custom toolbars and removes them
before exiting.

Cheers

Jacques said:
AutoNew works fine for me in Word 2004, except that it doesn't work for
the document that Word creates on starting up. I haven't tried the
others.

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Business Analyst, Consultant
Technical Writer.
Sydney, Australia +61 (0) 4 1209 1410
 
D

Daiya Mitchell

What Paul says is correct: AutoNew won't work for the blank document
because it doesn't fire the DocumentNew event.

Aha. John, *thank* you for settling this. :)

Sorry for my error, all! I picked the AutoNew/AutoOpen info up from WinWord
and never specifically clarified it for the Mac. It appears to work on my
machine, but that's just a coincidence.

Daiya
 
J

John McGhie [MVP -- Word and Word Mac]

Hi:

Top-posting if you can... WHen we're in a hurry, it saves all that
scrolling :)
Hi, I'm joining this discussion.
Welcome!

Following your postings, I managed to
set the default size and location for any new or opened document. i.e.
if I press Command+N it's perfect, or open any file. The only minor
problem now is when I Launch Word, then the default or Normal document
isn't aligned as in the macro settings.

If you're talking about toolbar alignment, that's right. There's a bug in
Mac Word VBA that ignores the positioning statements for toolbars. Sorry,
no cure!
Even selecting new from Project
Gallery is perfect. Is there something I overlooked?

No. It's a bug.
Best wishes,
JB

PS. Renaming macros can be done by copying and pasting the new name on
top of the old in the VB browser tab below. Trying to delete existing
name will cause shutdown of Word.

Well, true, but I would strongly advise people NOT to get into the habit of
re-naming macros. You'll get into a world of hurt in larger projects doing
that :)

Create them with the names you intend to use: make them descriptive :)

--

John McGhie <[email protected]>
Consultant Technical Writer, Microsoft MVP (Word, Word for Mac)
Sydney, Australia +61 (0)4 1209 1410

news:[email protected]...
 
J

John McGhie [MVP -- Word and Word Mac]

Hi Jacque:

Jacques said:
Hi John. The global template into which I tried to put an AutoOpen macro
was in fact in my Word Startup folder. But I'm surprised that you say a
global template MUST be there. In Tools>Templates and Add-ins there are
the options (a) to attach a document template, or (b) to add a global
template which is not already loaded. I just tried adding (as a global
template, not the document template) a template from outside the Startup
folder, and it seemed to work OK. Does Word use the term "global
template" in two different senses, sometimes including a template added
after start-up and sometimes not? Does a global template added after
start-up (if such a thing exists) behave differently from one loaded on
start-up?

Ah! My mistake. I neglected to mention that you can load Global Templates
using that dialog. I don;t use it, because it can be unreliable (if the
gloabl template is not found on next Word startup, it will not be loaded,
and then won't load correctly in future. So I like to put them all in
Startup so I know where they are :)

The distinction is that a Global Template (Whether loaded from Startup or by
Templates>Add...) is loaded by the application, before any documents load,
and is available to all documents that are open.

The Attached Template is loaded AFTER the document which calls it loads, and
resources within it are NOT available to any other documents that may be
open (unless they Attach the same template).

Whereas the NORMAL template is either loaded or created by the application
before anything else loads, and its resources are also available to all open
documents.

Normal is basically the "Lender of Last Resort" which is always guaranteed
to be present and is the last place Word looks for things. So you can have
an AutoOpen in Normal and one in the Global template and one in the Attached
Template, all with the same name. The one that runs will be the one in the
Attached Template.

This is worth remembering, although it's risky, it can be useful: You can
have multiple macros of the same name in context, provided they are in
different templates. Only ONE of them will AUOT-run: the one in closest
context.

You CAN override this context by explicitly calling the macro you want from
a named template, but for god's sake DON'T -- nobody will be able to
maintain your code -- including YOU!!

And don't go spending money on books on VBA for the Mac. All VBA on the Mac
will go away in a few months! Spend your money on AppleScript books.
Sorry, I don't understand that. It was the same code that worked OK if
put in the Normal template. And it was the only macro I had put in the
global template. But I'm certainly confused about "macro projects",
"modules", "procedures" etc. The Missing Manual isn't much help on this,
but I've ordered a couple of Woody Leonhard's books on Winword 2000
which I hope will make things clearer.

I know the "Missing Manual" series is highly revered, but I found that the
thing that is mainly missing in my copy of one of them is "content" :)

The error "ambiguous name" does not necessarily mean the name of a macro, it
can be the name of anything, such as a variable. The VBA compiler compiles
the whole Project: names must be unique within the project.

A "Project" is a "Template" for our purposes. A "Module" is a a collection
of macros: the thing that appears in the left column of the VBA Editor:
"NewMacros is an example, the default module created when you record things.
A "Procedure" is a single macro. "Sub" stands for "Subprocedure". There
are several other flavours: Functions are the one you will see most often.

Cheers
 
J

Jacques

John McGhie said:
Hi Jacque:



Ah! My mistake. I neglected to mention that you can load Global Templates
using that dialog. I don;t use it, because it can be unreliable (if the
gloabl template is not found on next Word startup, it will not be loaded,
and then won't load correctly in future. So I like to put them all in
Startup so I know where they are :)

Understood. Loading global templates after startup is yet another of
those options that Word offers, but you shouldn't accept.
And don't go spending money on books on VBA for the Mac. All VBA on the Mac
will go away in a few months! Spend your money on AppleScript books.

My top priority at the moment is to stop Word 2004 getting in my way (by
resizing my windows, shoving unwanted toolbars at me etc), and VBA seems
to be the simplest way of doing this. Would you agree? If so, I'll get
round to learning AppleScript later. I don't expect to be upgrading at
the first opportunity. If I hadn't switched to a Mac I'd still be using
Word 97.
I know the "Missing Manual" series is highly revered, but I found that the
thing that is mainly missing in my copy of one of them is "content" :)

I found the ones on OS X and GarageBand helpful, but the Office one is
disappointingly Microsoftian. It doesn't even warn you not to use Fast
Saves! I prefer Woody's tell-it-like-it-is approach. His Underground
Guide was what enabled me to get a grip on WinWord 6. Besides, you can
pick up books on Office 2000 pretty cheap now ...
 
L

little_creature

Hi,
You can by macro. I'm on PC now so I will not give you exact solution
just some tips:
1. start macros recorning
2. resize your window to size you like
3. stop macros recording
4. have a look on your macro at VBA, you should end up with something
like this:

Private Sub scale_down()
With ActiveWindow
.Width = 882
.Height = 675
End With
End Sub

(e-mail address removed) said the following on 8.9.2006 5:17:
 
J

jwelsh0787

Maximize the window size. Then press and hold "Ctrl" as you click the X on the window. It will save this as the default.
 

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