RE: Is there a way to run a macro upon opening a document?

From: Mister T (MisterT_at_discussions.microsoft.com)
Date: 08/12/04


Date: Thu, 12 Aug 2004 11:15:02 -0700

I think it should work if you go to the VB editor, open the "ThisWorkbook"
window and paste the following in that window (not in a module):

Private Sub Workbook_Open()

the code you want to run upon opening the workbook
    
End Sub

In other words, the macro above will be THE macro, it's not in addition to
your existing macro.

As an example, try the following first:

Private Sub Workbook_Open()

    Msgbox "Hello"
    
End Sub

Hopefully that one works...

"Beverly76" wrote:

> I'm not sure where to put this code to make it work. I tried Pasting it into
> the macro (before and after my command lines). And I tried pasting it just
> onto the VBA Editor. But when I opened the file, nothing happened.
>
>
>
> "Mister T" wrote:
>
> > Private Sub Workbook_Open()
> >
> > your code here
> >
> > End Sub
> >
> > "Beverly76" wrote:
> >
> > > I have a macro that I use to open a dbf file and saves it as and xls file
> > > because for some reason Access has trouble opening it as a dbf (just this one
> > > file-the others are o.k.) I would like the macro to run upon opening the
> > > Excel document file without any other prompting because then I could automate
> > > the action of opening the file through MS Access so that the user would not
> > > have to pay too much attention to the process.
> > >
> > > Any ideas?
> > >
> > >
> > > --
> > > Sincerely,
> > > Beverly76



Relevant Pages

  • Re: Exporting Hierarchy to Excel (Jack`s Macro)
    ... Now an empty Excel ... Sub dwn ... How exactly did you copy Jack's code into the VB editor? ... contains Jack's macro? ...
    (microsoft.public.project)
  • re:Printing messages with .tif attachments from Public Folder
    ... Create macro in Outlook XP to print attachments. ... - A Microsoft Visual Basic window will appear with a VbaProject.OTM ... "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ... Sub PrintTiffAttachments() ...
    (microsoft.public.outlook.printing)
  • Re: VBA Code Help - Creating a Dictionary
    ... VBA editing window. ... It will, by default, be called "Module1" ... Sub Test ... This means you now have a macro called "Test" in the module called Module1. ...
    (microsoft.public.word.vba.general)
  • Re: Need Help writing Print Macro
    ... menu and works on the active sheet but skips code for all but a specific ... Press Alt/F11 to open the VBA editor. ... Copy the macro into the editor. ... Private Sub Workbook_BeforePrint ...
    (microsoft.public.excel.programming)
  • Re: Exporting Hierarchy to Excel (Jack`s Macro)
    ... Now an empty Excel ... Sub dwn ... I checked the code that I pasted into VB editor, ... I selected the tasks and runed the Macro but The problem still exist. ...
    (microsoft.public.project)