I have been trying to create a macro to be executed every time I open the document. I tried to use the Open event, but it does not seem to be working. The code is below:

Private Sub Workbook_Open()
    Cells(3, 1) = "WOWWW"
End Sub  

(It might seem ridiculous but I am trying to make any chunk of code to work, to move further with the start-time macro).

Each time I open the file, the cell (A3) does not seem to be changing. Any ideas on this?

I don't know if it matters, but I don't open the file directly. I open it through opening the Excel program and then File Tab -> Open -> File. That is because I have a problem if I open the file directly, which is another matter.

  • It works for me. Are you sure you are saving as a macro-enabled workbook and you have macros enabled? You need to provide more information and tell us what you have already tried. I would suggest you try to narrow it down, e.g. create a new Excel workbook and check that macros are working at all. – James P Oct 30 '13 at 14:02
  • @James I have created an excel file, with a ton of other macros and subs written on it and already working, that's why I found this strange too. I want to do some things when the file starts, like a form of "initialization", but, as I stated above, it just does not work. – Noob Doob Oct 30 '13 at 14:16
  • Does the above macro work if you paste it into a new Excel file, i.e. does it only not work in one particular workbook? Have you got any third-party add-ons installed? Might be worth disabling them to be sure they're not somehow affecting things. – James P Oct 30 '13 at 14:20
  • @James just tried it on another excel file and it didn't work. Other,custom, macros I have copied from one file to another have worked. I do not remembering putting any add-ons on excel, except if you mean something else. – Noob Doob Oct 30 '13 at 14:22
  • Where is this code placed? Is it in ThisWorkbook? – CharlieRB Oct 30 '13 at 14:38

I don't think that the issue that you cannot open the file directly, and the inability of excel to run this code are unrelated. It seems that there is some corruption in the file.

As it seems Excel did not automatically pick up on this, I would suggest copying all the sheets to a new file, and use export and import on the code to recover the code.

Other methods to recover a corrupted file can be found here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.