View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default VBA script on document open or close

Joesph

Open a new workbook. Customize your as you wish.

FileSave As Type: scroll down to Excel Template(*.XLT) and select. Name your
workbook "BOOK"(no quotes). Excel will add the .XLT to save as BOOK.XLT.

Store this workbook in the XLSTART folder usually located at........

C:\Documents and Settings\username\Application Data\Microsoft\Excel\XLSTART

This will be the default workbook for FileNew or the Toolbar button FileNew

Do not use FileNew...Blank Workbook or you will get the Excel default workbook.

NOTE: Existing workbooks are not affected by these settings.

You can also open a new workbook and delete all but one sheet. Customize as
you wish then save this as SHEET.XLT in XLSTART folder also. It now becomes
the default InsertSheet.

More can be found on this in Help under "templates"(no quotes).


Gord Dibben Excel MVP


On Mon, 27 Nov 2006 10:45:10 +0800, "NickHK" wrote:

Joseph,
I guess you are trying to replace the default Excel workbook that is created
when you click FileNew, click the New icon.
I seems to remember (when using Excel2000) altering the files "Book.xls" and
Sheet.xls" so all new WBs and WSs create incorporate these changes. However,
now I'm using Excel2002, I do not find these files on my system, so can't
tell you from which file(s) Excel generates these from, i.e. Excel
equivalent to Word's Normal.dot.

You can achieve the same result in code with Application level Events though
www.cpearson.com/excel/AppEvent.htm

NickHK

"Joseph N." wrote in message
oups.com...
Thanks Helmut. However, that code does not work for me.

I pasted it into the VB editor area of a workbook, making sure that it
was the workbook itself and not a template or add-in to which I was
adding the code. I digitally signed it with an accepted certificate,
since my macro security is set to "high," then I saved the workbook as
book.xlt . Following Microsoft's instructions, I first saved it in the
location of my templates, but that didn't work. Then I tried saving it
in the program's folder for startup templates, and that didn't work.
Two problems occurred: first, new workbooks did not adopt that .xlt
file as a template. Second, even when I pasted that code into a
workbook, it did not display the desired behavior. I am using Office
2003 with all updates. Any idea what could be the problem?

JN

Helmut Weber wrote:
This one works for me:

Sub auto_close()
If ThisWorkbook.BuiltinDocumentProperties("Title") = "" Then
Application.Dialogs(xlDialogSummaryInfo).Show
End If
End Sub

Sub auto_open()
If ThisWorkbook.BuiltinDocumentProperties("Title") = "" Then
Application.Dialogs(xlDialogSummaryInfo).Show
End If
End Sub




Gord Dibben MS Excel MVP