Auto_Open

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 

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

Similar Threads


Back
Top