-1

I have the following peace of code to exec a xlam file when I open the excel file:

   Sub Auto_Open()
      Application.OnTime Now + TimeValue("00:00:05"), "readCsv"
   End Sub

   Sub readCsv()
      ....
   End Sub

I add it as Add-ins so every file I open has the xlam file on it. If there is no other excel file opened, it works perfectly but after that without closing the excel file I open a second one it does nothing. I need to exec the code even if there is another excel file opened. Is that possible?

I also try to do it writing the code in ThisWorkbook but the result is the same, If there is another excel file opened it does nothing.

Community
  • 1
  • 1
Iban Arriola
  • 2,526
  • 9
  • 41
  • 88
  • this is not enough code. how do u open the file? consider opening it readonly. Do you get an error? have you tried to debug-step through code? –  Aug 22 '13 at 09:11
  • Why is not enough? It doesn't matter what is inside the readCsv because it works well... the problem is that Auto_Open only works if there is no other excel file open and the same happens if I put readCsv in ThisWorkbook. I open the file just with double click on the excel file I want to open. Hope this explanation will help. – Iban Arriola Aug 22 '13 at 09:17
  • [first result in google](http://www.pcreview.co.uk/forums/auto_open-vs-workbook_open-t953960.html) –  Aug 22 '13 at 09:20
  • It didn't work... First I replace Auto_open() for Workbook_open() and it wasn't working even with the first open excel file. Then I saw on Internet that Workbook_Open() must be in ThisWorkbook and I put it there. For the first opened excel file it worked but not for the second one... so basically Auto_open() and Workbook_open() gave me the same result. – Iban Arriola Aug 22 '13 at 09:57
  • you realize you have to have the code in each file you open in order to execute the Workbook_Open() –  Aug 22 '13 at 10:58
  • I create an xlam file and it works in all excel files... but only if there isn't other excel file opened. – Iban Arriola Aug 22 '13 at 14:24

2 Answers2

0

To use your macro in any of the worksheet opened (irrespective of name) you can only possible do it by using a personal workbook Here is the Link

If the above doesnt suits you can prepare Add-ins and install it for users (Google for it if this is the case)

EDIT:

How to get add in in all opened files....

Goto File - Option - Quick Access Toolboar - From the dropdown "Choose Command from" - select Macros then select add-in macro - Add it, Below there would be a modify button Select the icon you like from it - OK

Now you will be able to see the icon with the addin function linked on top of the excel - click it for functioning, it will remain there forever ( if missed you can reapply the settings)....

The procedure are for 2010, for 2007 it should be similar....for 2003 there is a different way to achieve it...

Vasim
  • 3,052
  • 3
  • 35
  • 56
  • I have my macro as an Add-in. I create an xlam file and put it in the regedit. This is done well because it is working in all files that I open. The problem is that if I have another excel file opened before the second one do nothing. – Iban Arriola Aug 22 '13 at 14:27
  • Thanks for the answer. What I want is to start the macro when I open the excel file not to create a button to make it. For that create a xlam file and add it in add-ins. But the problem that I have is that it only execs when there is no other excel file opened. – Iban Arriola Aug 22 '13 at 15:01
0

Copy the .xlam to C:\Users[user]\AppData\Roaming\Microsoft\Excel\XLSTART. It will load every time you open Excel.

mcfroob
  • 1,044
  • 1
  • 11
  • 13