0

I was just introduced to VBA. However, on saving my first excel file with VBA code, with .xlsm extension (I was advised to do so), and then reopening that saved file, I realized that all the VBA code had disappeared and the cells in which I had used the user-defined functions threw errors. Saving the workbook as .xlsx instead of .xlsm also didn't help. When I tried saving the VBA module, it showed that FUNCRES.XLAM is read-only and hence cannot be modified, and so try saving it at a different location. Doing so, saved an excel file which on opening showed a pop-up message that it's corrupt so can't be opened. Then I gave all permissions to FUNCRES.XLAM and it is NOT read-only. But the problem still prevailed. What should I do? Can someone please help me?

PS: It is Windows 10, Office 2016.

1 Answer 1

3

Your VBA code needs to be saved in a module within the same workbook in which you are working. This will probably be listed as VBAProject(Book1)

There will likely be other projects listed in the Project Explorer window of the VBA GUI, but your code will not get saved with those modules.

These are related to add-ins, and not to your workbook.

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

A quick little hack to make sure that your code is in a module associated with the file you are working in would be to switch on the macro recorder and do something simple like copy one cell to another to generate some code. This will create a module within the workbook you working in so that you KNOW it's the right one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.