Running macro automatically on document open (Word 2007)

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

:z:

Thread Starter
Joined
Feb 27, 2008
Messages
128
I am trying to get Word 2007 to hide my unused status bar, but unfortunately there does not seem to be an interface toggle for this in the 2007 version. I then tried to copy and paste a macro for this, which worked, but only when I manually ran it each time I opened a document. Is there a way I can set it to run automatically alongside another macro I have running when a document opens?

I know nothing about macro language...I just copied and pasted the code. So being as descriptive as possible with your solution would help me.

Thanks!


Here's the code (which currently works) for automatically adjusting the zoom on my documents:

Public Sub AutoOpen()
ActiveWindow.ActivePane.View.Zoom.Percentage = 100
End Sub


Here's the code for hiding the status bar that I want to also run automatically whenever I open a document:

Application.CommandBars("Status Bar").Visible = False
 

:z:

Thread Starter
Joined
Feb 27, 2008
Messages
128
firefytr:

Thanks for the reply! I know this is probably an ignorant question, but how do I save it in my Normal.dotm file? Say, for example, I open Word and there's a blank document automatically loaded into it. I then open Macros and run my command. I exit the Macros window and I am presented with the blank document again (only this time my status bar is gone). Then what? When I save it just saves a .doc file.

Thanks again!
 

:z:

Thread Starter
Joined
Feb 27, 2008
Messages
128
firefytr:

Thanks! I should have some time later tonight to sort through all this stuff and hopefully I can figure it out. Will post my results afterwards.
 

:z:

Thread Starter
Joined
Feb 27, 2008
Messages
128
firefytr:

I didn't see where in that link it talked about writing to the Normal.dotm file. I tried over-writing the physical file with a Save As to no avail. I also tried the AutoExec code that the link you gave me mentioned, but couldn't get it to work. Here's what I'm using:

Sub AutoExec()
Application.CommandBars("Status Bar").Visible = False
End Sub


Also tried this code that it mentioned as well, which did not work either:

Private Sub oApp_DocumentOpen(ByVal Doc As Document)
Application.CommandBars("Status Bar").Visible = False
End Sub
 

:z:

Thread Starter
Joined
Feb 27, 2008
Messages
128
Update:

I've been able to assign the macro to a button, and then a keyboard shortcut, so I can remove it manually each time more easily, but it would still be nice to figure out how to do it automatically.

The Normal.dotm shows my macros in it (I guess that's how the custom button and keyboard shortcut works each time).
 
Joined
Jul 25, 2004
Messages
5,456
Did you read the entire article? It tells you that you need to create a Class Module.

Although reading more into the Word 2007 VBA Object Model, it doesn't appear that the status bar is supported anymore, that it is more of a permanent fixture in the application.
 

:z:

Thread Starter
Joined
Feb 27, 2008
Messages
128
firefytr:

I read it, but I didn't understand most of it. :confused:

I'm sorry, I really am a novice at this sort of thing and I just figured there would be code I could copy and paste like what I did for the automatically adjusting the zoom whenever a document was opened. There's a lot that I would need to have explained in that article, and judging from your last post, you don't think getting rid of the status bar on document open is even possible now...?

Thanks for your patience and persistence. :)
 

:z:

Thread Starter
Joined
Feb 27, 2008
Messages
128
I'm sure this is a rather naïve thing to say, but Word doesn't just have an option to just push my custom macro button or execute the shortcut for my custom macro whenever a document is opened? Like a checkbox in the macros menu that says "run on document open"? Thanks again.
 
Joined
Jul 25, 2004
Messages
5,456
That is what I read in the help files, and the Status Bar is not even a valid command bar in the 2007 object model. Check it out with this code...

Code:
Sub ListAllBars()
    Dim s As String, i As Long
    With Application
        For i = 1 To .CommandBars.Count
            If i Mod 2 = 0 Then
                s = s & .CommandBars(i).Name & vbNewLine
            Else
                s = s & .CommandBars(i).Name & " | "
            End If
        Next i
    End With
    MsgBox s
End Sub
Had too many command bars, so I had to break it up into two per line. You will see Status Bar in there, but what the help file lined out, it is not able to have its visible property set to false. I can get the AutoExec routine to run, but the command bar does not hide.

So to summarize what that website said, create a Class Module in Normal.dotm file, rename the module ThisApplication. Ensure this code is in that module...
Code:
Option Explicit

Public WithEvents oApp As Word.Application
Insert a standard Module, ensure this code is in it...
Code:
Option Explicit

Dim oAppClass As New ThisApplication

Public Sub AutoExec()
    Set oAppClass.oApp = Word.Application
End Sub
You would then use your line like this (even though it doesn't work)...
Code:
oAppClass.oApp.Application.CommandBars("Status Bar").Visible = False
Make sense?
 

:z:

Thread Starter
Joined
Feb 27, 2008
Messages
128
firefytr:

No, it doesn't make sense, but I'll try to figure it out when I get home tonight. :eek:

But just to clarify, what exactly doesn't work? Is the procedure you outlined a work-around that ultimately achieves what I'm wanting, or are you saying that even your work-around doesn't work (and there's no solution yet)?
 
Joined
Jul 25, 2004
Messages
5,456
Hi, sorry for the confusion. I'm saying in Word 2007 I don't think what you're asking can be done. In 2000 - 2003 it can though (through the solution supplied above).
 

:z:

Thread Starter
Joined
Feb 27, 2008
Messages
128
firefytr:

Ah, thanks anyway then. In 2000-2003 it wasn't an issue, though, as there was a toggle in the UI to turn off the status bar for all documents. Why they removed that option is beyond me.
 

:z:

Thread Starter
Joined
Feb 27, 2008
Messages
128
Anyone else know how to remove the status bar in Word 2007 (all of Office, actually)? I don't care how it's done or if it's permanent...I just want the status bar gone. Thanks!
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top