#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Auto_Open

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default 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.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
AUTO_OPEN Bob Barnes Excel Discussion (Misc queries) 2 February 6th 08 03:03 AM
Auto_open and more.... pcor New Users to Excel 2 December 1st 06 02:07 AM
auto_open? Jack Sons Excel Discussion (Misc queries) 0 February 22nd 05 09:16 PM
XLA auto_open jc Excel Programming 0 October 6th 04 12:50 AM
Beyond AUTO_OPEN WarrenR Excel Programming 2 February 27th 04 03:57 AM


All times are GMT +1. The time now is 04:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"