![]() |
BeforeFileOpen Event
macros run from workbooks. Macros don't run until the workbook is open.
short answer: NO. Also, you can't really look through a closed workbook. Perhaps you can cobble together some solution using application.Screenupdating = False (but not in the workbook you are opening). -- Regards, Tom Ogilvy "Boba" wrote in message ... BlankHi, I need to look through and, if necessary, modify a file before Excel opens it. Is there an event BeforeFileOpen? Thnks. Boba |
BeforeFileOpen Event
Here is some code that I have used to search an excel file when it is opened.
It has to be saved as an addin. It listens for a workbook being opened and allows you to do something with that workbook. Here is the class module code... Option Explicit Private WithEvents xlApp As Excel.Application Private Sub Class_Initialize() Set xlApp = Excel.Application End Sub Private Sub xlApp_WorkbookOpen(ByVal Wb As Workbook) Call Main End Sub Private Sub Main() MsgBox "Tada" End Sub The above code needs to be made pasted into a class module Here is the Module code... Option Explicit Public evtEvents As clsXLEvents Public Sub Auto_Open() Set evtEvents = New clsXLEvents End Sub If you are unclear about creating module, class modules or addins just reply back and we can give you some more help HTH "Boba" wrote: BlankHi, I need to look through and, if necessary, modify a file before Excel opens it. Is there an event BeforeFileOpen? Thnks. Boba |
BeforeFileOpen Event
Use application.GetOpenFilename to put up the dialog, then use the results
to read the file. then when you are satisfied, open it in excel. -- Regards, Tom Ogilvy "Boba" wrote in message ... "Tom Ogilvy" wrote in message ... macros run from workbooks. Macros don't run until the workbook is open. short answer: NO. I want my micros (already loaded with an add-in) to scan a newly opened file after user selects it in OpenFileDialog but before the actual data records are read into worksheet. Also, you can't really look through a closed workbook. Those files are not xls workbooks. Perhaps you can cobble together some solution using application.Screenupdating = False (but not in the workbook you are opening). That's exactly the problem I want to work around: Excel can not open the file. -- Regards, Tom Ogilvy Thank you. Boba |
BeforeFileOpen Event
To the OP:
Just to clarify, just like any Open event, this fires after the workbook is opened. http://www.cpearson.com/excel/appevent.htm Chip Pearson's page on application level events. -- Regards, Tom Ogilvy "Jim Thomlinson" wrote in message ... Here is some code that I have used to search an excel file when it is opened. It has to be saved as an addin. It listens for a workbook being opened and allows you to do something with that workbook. Here is the class module code... Option Explicit Private WithEvents xlApp As Excel.Application Private Sub Class_Initialize() Set xlApp = Excel.Application End Sub Private Sub xlApp_WorkbookOpen(ByVal Wb As Workbook) Call Main End Sub Private Sub Main() MsgBox "Tada" End Sub The above code needs to be made pasted into a class module Here is the Module code... Option Explicit Public evtEvents As clsXLEvents Public Sub Auto_Open() Set evtEvents = New clsXLEvents End Sub If you are unclear about creating module, class modules or addins just reply back and we can give you some more help HTH "Boba" wrote: BlankHi, I need to look through and, if necessary, modify a file before Excel opens it. Is there an event BeforeFileOpen? Thnks. Boba |
BeforeFileOpen Event
I absolutely agree. But this is as close to Before Open as you are going to
get with VBA... that I know of. The only other area to look at would be an API call to catch the Operating System openeing the file and that sounds really problematic. The VBA only begins execution after the OS has "handed it the open file". If this won't work then ??? Best of Luck! "Tom Ogilvy" wrote: To the OP: Just to clarify, just like any Open event, this fires after the workbook is opened. http://www.cpearson.com/excel/appevent.htm Chip Pearson's page on application level events. -- Regards, Tom Ogilvy "Jim Thomlinson" wrote in message ... Here is some code that I have used to search an excel file when it is opened. It has to be saved as an addin. It listens for a workbook being opened and allows you to do something with that workbook. Here is the class module code... Option Explicit Private WithEvents xlApp As Excel.Application Private Sub Class_Initialize() Set xlApp = Excel.Application End Sub Private Sub xlApp_WorkbookOpen(ByVal Wb As Workbook) Call Main End Sub Private Sub Main() MsgBox "Tada" End Sub The above code needs to be made pasted into a class module Here is the Module code... Option Explicit Public evtEvents As clsXLEvents Public Sub Auto_Open() Set evtEvents = New clsXLEvents End Sub If you are unclear about creating module, class modules or addins just reply back and we can give you some more help HTH "Boba" wrote: BlankHi, I need to look through and, if necessary, modify a file before Excel opens it. Is there an event BeforeFileOpen? Thnks. Boba |
BeforeFileOpen Event
BlankHi,
I need to look through and, if necessary, modify a file before Excel opens it. Is there an event BeforeFileOpen? Thnks. Boba |
BeforeFileOpen Event
"Tom Ogilvy" wrote in message
... macros run from workbooks. Macros don't run until the workbook is open. short answer: NO. I want my micros (already loaded with an add-in) to scan a newly opened file after user selects it in OpenFileDialog but before the actual data records are read into worksheet. Also, you can't really look through a closed workbook. Those files are not xls workbooks. Perhaps you can cobble together some solution using application.Screenupdating = False (but not in the workbook you are opening). That's exactly the problem I want to work around: Excel can not open the file. -- Regards, Tom Ogilvy Thank you. Boba |
BeforeFileOpen Event
Thanks a lot, Gentlemen.
Boba |
BeforeFileOpen Event
Thanks to all of you. Boba.
|
All times are GMT +1. The time now is 06:10 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com