General discussion

Locked

Excel Macros: Starting up and Exiting

By GCHeels ·
I need to build a macro that will start as soon as I open the Excel file, do some processing, and exit Excel. What I intend to do is, schedule the Excel file to run at night, retrieve data from an Access database, save the file and exit Excel. I need to know how to automatically start the macro when the spreadsheet file opens and after it finishes it's processing, save the file (with no prompt to overwrite the file) and close Excel. Thanks.

This conversation is currently closed to new comments.

11 total posts (Page 1 of 2)   01 | 02   Next
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Excel Macros: Starting up and Exiting

by DKlippert In reply to Excel Macros: Starting up ...

You may be looking for:

Auto_Open
Auto_Close

But also look at:


www.cpearson.com/excel/ontime.htm

Collapse -

Excel Macros: Starting up and Exiting

by GCHeels In reply to Excel Macros: Starting up ...

Poster rated this answer

Collapse -

Excel Macros: Starting up and Exiting

by ammartq In reply to Excel Macros: Starting up ...

Start excel file in which you need to use the macro. Press Alt+F11 (both keys together).
Double-click "ThisWorkbook" from left, top box. Select "Workbook" from top center combo box. You will see following function in main text area:

Private Sub Workbook_Open()

End Sub

Whatever you write between these two lines will be run when your excel file starts.

Collapse -

Excel Macros: Starting up and Exiting

by GCHeels In reply to Excel Macros: Starting up ...

Poster rated this answer

Collapse -

Excel Macros: Starting up and Exiting

by ammartq In reply to Excel Macros: Starting up ...

I need to know why my above answer was rejected although it was correct. Please specify your reason to reject the answer.

Collapse -

Excel Macros: Starting up and Exiting

by GCHeels In reply to Excel Macros: Starting up ...

Your answer may be correct, but it's like saying to write a program, you 1)turn on the computer, 2)write the program, 3)then turn the computer off. I also needed to know what went between the lines as well. Besides, I just tried it, and the directions were not correct. When I press Alt-F11, "This Workbook" is not in the upper left combo box, it's in the main window and you have to click on it before it appears in the combo box........

Collapse -

Excel Macros: Starting up and Exiting

by ammartq In reply to Excel Macros: Starting up ...

You said you "need to know how to automatically start the macro when the spreadsheet file opens and after it finishes it's processing, save the file (with no prompt to overwrite the file) and close Excel."

Thats what I told you. If you want me togive you the code to get the data from Access, you should have clearly specified that in the question. Rather you said that YOU intend to do... so I thought you will write the data collection yourself. :)

Collapse -

Excel Macros: Starting up and Exiting

by GCHeels In reply to Excel Macros: Starting up ...

The question was auto-closed by TechRepublic

Collapse -

Excel Macros: Starting up and Exiting

by FirstPeter In reply to Excel Macros: Starting up ...

Perhaps this will help:

1. Start Excel.
2. Press Alt-F11 to enter the Visual Basic Editor.
3. Select the "ThisWorkbook" branch under "VBAProject(Book1)" by double-clicking on it [Book1 is the name of your Excel workbook].
4. The code you'll want to type in the code pane is:

Private Sub Workbook_Open()
<< Your data retrieval code here >>
ActiveWorkbook.Close savechanges:=True
End Sub

Does that help?

Collapse -

Excel Macros: Starting up and Exiting

by GCHeels In reply to Excel Macros: Starting up ...

The question was auto-closed by TechRepublic

Back to Software Forum
11 total posts (Page 1 of 2)   01 | 02   Next

Related Discussions

Related Forums