BeforeFileOpen Event

  • Thread starter Thread starter Tom Ogilvy
  • Start date Start date
T

Tom Ogilvy

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).
 
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
 
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.
 
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!
 
BlankHi,
I need to look through and, if necessary, modify
a file before Excel opens it. Is there an event
BeforeFileOpen? Thnks. Boba
 
Tom Ogilvy said:
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.

Thank you.
Boba
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top