Autorun a macro upon opening of excel file

MrDB4Excel

Board Regular
Joined
Jan 29, 2004
Messages
125
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
 

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

mole999

Moderator
Joined
Oct 23, 2004
Messages
10,368
Office Version
2019, 2016, 2013
Platform
Windows
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
 

MrDB4Excel

Board Regular
Joined
Jan 29, 2004
Messages
125
Many thanks, mole999. Second code worked. First did not, but no matter because the second code works very well.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,886
Messages
5,489,536
Members
407,697
Latest member
Lotte_4

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top