# Running macro automatically on document open (Word 2007)



## :z: (Feb 27, 2008)

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_


----------



## Zack Barresse (Jul 25, 2004)

Hi there, welcome to the board!

Set the routine in your Normal.dotm file.

HTH


----------



## :z: (Feb 27, 2008)

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!


----------



## Zack Barresse (Jul 25, 2004)

Hi,

This will probably help you out more than I could explain, plus I don't have to reinvent the wheel. 

http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm

HTH


----------



## :z: (Feb 27, 2008)

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: (Feb 27, 2008)

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: (Feb 27, 2008)

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).


----------



## Zack Barresse (Jul 25, 2004)

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: (Feb 27, 2008)

firefytr:

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

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: (Feb 27, 2008)

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.


----------



## Zack Barresse (Jul 25, 2004)

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...


```
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...

```
Option Explicit

Public WithEvents oApp As Word.Application
```
Insert a standard Module, ensure this code is in it...

```
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)...

```
oAppClass.oApp.Application.CommandBars("Status Bar").Visible = False
```
Make sense?


----------



## :z: (Feb 27, 2008)

firefytr:

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

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)?


----------



## Zack Barresse (Jul 25, 2004)

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: (Feb 27, 2008)

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: (Feb 27, 2008)

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!


----------

