Auto_Open
This is possible. However, I think you have to create an Application
Level Event and pass that down to your macro. This requires using a
class module, ThisWorkbook procedure, and a regular module
We'll start with the Class Module.
In Personal.xls add a class module and paste this code:
Option Explicit
Public WithEvents App As Application
Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
If Wb.Name = "Albert.csv" Then
YourMacro 'This Runs a macro with the name "YourMacro" Rename
as needed
End If
End Sub
Now onto the ThisWorkbook event
Under the "ThisWorkbook" code paste this:
Option Explicit
Private Sub Workbook_Open()
Set AppClass.App = Application
End Sub
Now add a regular module and add this:
Option Explicit
Public AppClass As New EventClass
Sub YourMacro()
MsgBox ActiveWorkbook.Name
End Sub
That should do it.
Charles Chickering
xl Geek
Alastair79 wrote:
Is it possiable to say if a .csv file with the name "Albert" is open then run
the following macro else don't run anything. The file does not always exist
so can't just set it to that specific file, will have to be saved on the
Personal.xls
Thanks............... Alastair.
|