Results 1 to 3 of 3

Thread: Autorun a macro upon opening of excel file
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Jan 2004
    Location
    Mariánské Lázně, Czech Republic
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Autorun a macro upon opening of excel file

    I am trying to get a macro to autorun when I open a workbook.
    I want this macro to run automatically as soon as I have selected the "Update" selection that appears in the "This workbook contains links to one or more external sources that could be unsafe."
    Obviously these sources exist only on my PC and thus are trusted, so this is not an issue.
    When I select "Update" I expect the macro to autorun, but alas it does nothing.
    The specific macro I want to run is called RunThemAll and it goes as follows:
    Sub RunThemAll()
    Range("T12").Select
    Application.Run "USD2CZK"
    Range("T14").Select
    Application.Run "EUR2CZK"
    Range("T16").Select
    Application.Run "CZK2EUR"
    Range("T18").Select
    Application.Run "RUB2EUR"
    Range("T20").Select
    Application.Run "EUR2RUB"
    Range("A2").Select
    Range("J23").Select
    End Sub

    I have tried the following and all of these were inserted in a double click of "ThisWorkbook" and not added in a module.
    Each of the Application.Run "USD2CZK", "EUR2CZK", "CZK2EUR", "RUB2EUR" & "EUR2RUB" all exist in separate modules as seen below in the RunThemAll macro.
    What am I doing wrong?

    Private Sub Workbook_Open()
    Call RunThemAll
    End Sub

    &

    Private Sub Workbook_Open()
    Sub RunThemAll()
    Range("T12").Select
    Application.Run "USD2CZK"
    Range("T14").Select
    Application.Run "EUR2CZK"
    Range("T16").Select
    Application.Run "CZK2EUR"
    Range("T18").Select
    Application.Run "RUB2EUR"
    Range("T20").Select
    Application.Run "EUR2RUB"
    Range("A2").Select
    Range("J23").Select
    End Sub
    End Sub

    &

    Private Sub Workbook_Open()

    End Sub
    Sub RunThemAll()
    Range("T12").Select
    Application.Run "USD2CZK"
    Range("T14").Select
    Application.Run "EUR2CZK"
    Range("T16").Select
    Application.Run "CZK2EUR"
    Range("T18").Select
    Application.Run "RUB2EUR"
    Range("T20").Select
    Application.Run "EUR2RUB"
    Range("A2").Select
    Range("J23").Select
    End Sub
    Dwight Baker

  2. #2
    Moderator mole999's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    9,856
    Post Thanks / Like
    Mentioned
    16 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Autorun a macro upon opening of excel file

    Code:
    Private Sub Workbook_Open()
    RunThemAll()
    End Sub
    Sub RunThemAll()
    Range("T12").Select
    Application.Run "USD2CZK"
    Range("T14").Select
    Application.Run "EUR2CZK"
    Range("T16").Select
    Application.Run "CZK2EUR"
    Range("T18").Select
    Application.Run "RUB2EUR"
    Range("T20").Select
    Application.Run "EUR2RUB"
    Range("A2").Select
    Range("J23").Select
    End Sub
    
    or
    
    Private Sub Workbook_Open()
    Range("T12").Select
    Application.Run "USD2CZK"
    Range("T14").Select
    Application.Run "EUR2CZK"
    Range("T16").Select
    Application.Run "CZK2EUR"
    Range("T18").Select
    Application.Run "RUB2EUR"
    Range("T20").Select
    Application.Run "EUR2RUB"
    Range("A2").Select
    Range("J23").Select
    End Sub
    • Yes I know there are better ways to do it. I just wish I knew them. - 97, 2003, 2007, 2010, 2013, 2016 & 2019
    • I wear my ignorance openly, excel is not my chosen career, its a means to an ends
    • Posting Guidelines Want to post well laid out questions and answers Translate Excel Versions
      Code:
      [CODE ]Put Your Code[/ CODE]
    • Settings > General Settings (on the left) scroll to the bottom, > Miscellaneous Options > Use ENHANCED
    • X-Posting Guidelines Rule 13 > CHART STUFF

  3. #3
    Board Regular
    Join Date
    Jan 2004
    Location
    Mariánské Lázně, Czech Republic
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Autorun a macro upon opening of excel file

    Many thanks, mole999. Second code worked. First did not, but no matter because the second code works very well.
    Dwight Baker

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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