+ Reply to Thread
Results 1 to 2 of 2

Makro to Run on Open Workbook

  1. #1
    Rob Fenn
    Guest

    Makro to Run on Open Workbook

    I realise this is probably a very simple question but I would be grateful
    for any help offered.

    I have a workbook that has formula's linked to another worksheet.
    Unfortunately the sheet it is linked to is a csv file so the links will not
    update without the sheet being open.

    Therefore I wanted to write a makro that opens the csv file and then closes
    it again. I have managed to do that with the record Makro command however I
    do not know how to get this Makro to run automatically on the worksheet
    being opened.


    ChDir "H:\SHARED"
    Workbooks.Open Filename:="H:\SHARED\susprecpt.csv"
    ActiveWindow.Close
    ActiveSheet.ShowAllData

    Thanks for your help

    Rob



  2. #2
    Tom Ogilvy
    Guest

    Re: Makro to Run on Open Workbook

    go into the VBE and click on the ThisWorkbook entry for your project in the
    project explorer. Select view code and this should produce the Workbook
    level module. In the dropdowns at the top of the module select Workbook
    from the left one and Open from the right one.

    This should put in the sub declarations:

    Private Sub Workbook_Open()

    End Sub

    Put your code in this procedure

    Private Sub Workbook_Open()
    ' you don't need to Chdir to open the file
    'ChDir "H:\SHARED"
    Workbooks.Open Filename:="H:\SHARED\susprecpt.csv"
    ActiveWindow.Close
    If Activesheet.AutoFilterMode = True then
    ActiveSheet.ShowAllData
    End Sub
    End sub

    See Chip Pearson's page on Events
    http://www.cpearson.com/excel/events.htm
    --
    Regards,
    Tom Ogilvy

    "Rob Fenn ntlworld.com>" <robfenn.mp<at> wrote in message
    news:[email protected]...
    > I realise this is probably a very simple question but I would be grateful
    > for any help offered.
    >
    > I have a workbook that has formula's linked to another worksheet.
    > Unfortunately the sheet it is linked to is a csv file so the links will

    not
    > update without the sheet being open.
    >
    > Therefore I wanted to write a makro that opens the csv file and then

    closes
    > it again. I have managed to do that with the record Makro command however

    I
    > do not know how to get this Makro to run automatically on the worksheet
    > being opened.
    >
    >
    > ChDir "H:\SHARED"
    > Workbooks.Open Filename:="H:\SHARED\susprecpt.csv"
    > ActiveWindow.Close
    > ActiveSheet.ShowAllData
    >
    > Thanks for your help
    >
    > Rob
    >
    >




+ 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