on the excel's startup i want to set a cell value to zero

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

on the excel's startup i want to set a cell value to zero.

Sub initialization()

Range("Input_Output_Sheet!D9").Value = 0
End Sub

is there a way to run this macro at the excels startup automatically
 
Michael,

Presuming you mean when a certain workbook is opened, not when Excel starts
up, you want to initialize that cell, put this in the ThisWorkbook module of
the workbook:

Private Sub Workbook_Open()
Range("Input_Output_Sheet!D9").Value = 0
End Sub

If you really want to do this to a certain workbook when Excel is started
up, I think you'll have to put a Workbook_Open macro in a workbook that is
started via the Startup folder, or in Tools - Options - General - "At
startup, open files in." That macro will need to open the workbook that's
to be changed (unless it's the workbook that's auto-opening) and make the
change.
 
i found the answer
Sub Auto_Open()
'
'
Range("Input_Output_Sheet!D9").Value = 0
End Sub
 
Michael,

Using AUto_Open in a regular module is OK, but may not always be supported.
It's a holdover from earlier versions of Excel that didn't have event-fired
subs (like Workbook_Open). Just thought it'd be worth a mention.
 
The Sub Auto_Open() is the one you want for a specific workbook.
Whatever code you put in that routine will execute each time the
workbook is opened. If you don't want the code to execute on open,
open Excel first and hold down the the SHIFT key while opening the
file. I use this functionality to automatically query an Oracle
database and then produce a report.

I don't know about the first reply - haven't tried it.
 
Back
Top