+ Reply to Thread
Results 1 to 2 of 2

Auto_Open

  1. #1
    Alastair79
    Guest

    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. #2
    Die_Another_Day
    Guest

    Re: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1