Macro-Enabled Template keeps opening original document when macro is run - excel

I made a series of macros on a document called 'Prac.xlsm'. I then saved the document as a Macro-Enabled template. When I run the first macro in the template it works but it also opens my original document titled Prac. The macro doesn't do anything to that original document though.
I tried to step through the templates macro and that works without opening up the original.
I then tried renaming the original file which resulted in an Excel popup saying "Sorry, we couldn't find ..file path & name for the Prac file.. Is it possible it was moved, renamed or deleted?" I can't see anywhere in the code where it refers to the file name Prac.xlsm. And because stepping through the code works without opening up the original file it has me stumped.
Any help would be appreciated.
Thank you.

Discovered it was because I was accessing the macros from the ribbon as I customized it. Unsure why but if I trigger the macros from the Developer tab they work.

Related

create and distribute Excel add in

I have created an extensive macro in excel, that I now want to distribute. I decided I want to do this by saving the macro as add in to a shared network, where all of my collegues have access to it. This way maintaining the macro will be way easier, as I am sure that there are plenty of updates, and bugfixing to come.
I have never created an add in before, so I read several online tutorials + stack overflow questions about it. Up until now I always saved my macros in personal.xlsb, likewise with the macro I now want to save as add in.
My first attempt was to simply save the workbook, where I run the macro, as .xlam, which did not work (I guess because the macro was not saved in that workbook, but in the personal.xlsb).
So I deleted the macro from the personal.xlsb, opened a new workbook, opened the VBA editor, created a new module in that workbook and inserted my code. I then saved the workbook as .xlam. I checked that in the VBA Editor the IsAddin is set to True.
From here it gets confusing somehow. When I open the .xlam file there are no worksheets in it, the add-in is loaded, but the macro does not show up in "Macros", even though the code shows up in the Editor.
When
However the .xlam is still empty when I open it - no code to be seen.
When I open another workbook and load the add-in, in the VBA editor the add-in does show up, and the module with the code of the macro is there as well. But when I click on "macro" it does not show up.
When I open a different Excel file, the add-in is loaded as well (in Excel-add-ins the box is ticked), the module does not show up, and in the VBA editor the .xlam also does not show up.
I have saved, closed, opened, and restarted several times. I have checked if the add-in is saved anywhere else - it was, but I deleted all .xlam files (as non of them worked anyway), and repeated my attempts stated above. When I load the .xlam from the shared network it seems to save itself into the addin folder of microsoft (I guess that is what it should do when it is loaded).
I would really appreciate if someone could help me with how to properly set this up.
I have:
a VBA code that runs fine, when I run it as macro.
I want
to save it to a shared network as add-in, and get it to run.
Edit1:
the add-in shows up in the active add-ins section in options:

xltm file opens when I run a macro

I have a macro enabled template (trainings.xltm file). I create a new Excel workbook from that template (trainings1). That works fine. However, when I run a macro in trainings1, that macro is executed but opens trainings.xltm. If I save trainings1 as 07112017.xlsm and run a macro in that file, the trainings.xltm is opened, too. So there is no difference between the newly created file and a saved file.
I don't want trainings.xltm to open automatically every time i run a macro. How can I stop that?
I have the macros in the ribbon, I have checked they point to the .xlsm file.
Any ideas are very welcome.
Regards,
Michael
I figured it out. The ribbon is global, I think that's why the newly created file always opens the template.
I created a custom ui file using the office-ribbonx-editor (https://github.com/fernandreu/office-ribbonx-editor) from Fernando Andreu.
Next I deleted my macros from the ribbon. Now the new file does not open the template. As a positive side effect, my ribbon is only visible in files created from that template and not in other files. They wouldn't work there anyway.

View removed VBA code after repair of Excel file

I am getting an error when opening excel: We found a problem with some content in XXX. Do you want us to try and recover as much as we can? if you trust he source of this workbook, click Yes."
clicking Yes, "fixes" the issue but deletes a lot of VBA code, two weeks worth.
Whatever the issue it was introduced yesterday, I do not want to redo two weeks worth of coding. Is there anyway I can view what was removed, or open the VBA in notepad++ or something without opening the excel?
I opened another excel workbook and tried all the different options for the argument XlCorruptLoad in the Workbooks.Open to open the corrupt workbook. I noticed that there were two non existing sheets created in the project explroer of the corrupt workbook that had the code in there. I am not sure if it did that s a result of what I did or it was there all along and I did not notice it
Note that the reason I had a corrupted data is because the code was extracting a list and putting it in a cell validation formula..i guess I overloaded it.

VBA Module disappears after saving Excel workbook

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.
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.

Excel Hyperlinks to Excel documents not working

We have a excel document that contains a ton of Hyperlinks to other Excel Documents & File Paths all located on our network. All of a sudden the Hyperlinks to the Excel Documents have broken, Excel will state the error below;
Some files can contain viruses or otherwise be harmful to your computer. It is important to be certain that this file is from a trustworthy source.
Would you like to open this file? OK/Cancel
We click OK and nothing will happen. Opening file paths is still working fine and I've created another Excel document which has links to a PDF, a File Path, a Word Doc & an Excel Doc. Still only the Excel that isn't working.
I have followed several articles online that suggest how to disable the warning message,below is a well detailed article for 2007/2010 but we had tried to adapt it for 2013/6. Nothing I have tried is working, does anyone on Stack have any suggestions?
https://support.microsoft.com/en-gb/help/925757/how-to-enable-or-disable-hyperlink-warning-messages-in-2007-office-pro
We are using Office 2013/6 Standard/Professional.
Any help would be greatly appreciated!!
Many thanks,
Sean
This happens when you copy the excel file to different location:
You can do test: place hyperlink into 1 cell save it, and then copy the file to another location: you can see that hyperlink of your copied excel file would not work.
However when you choose the same file to "Save As": the hyperlink of the saved file in different location will work.
For excel internal hyperlinks (hyperlinks to other worksheet cells) similar thing happens when you rename the file: hyperlinks won't work, but they will work if you choose to "Save As".
This means, the solution to this problem would be: copy the excel file to it's original location and name it with the original name (when hyperlinks were working). In this case hyperlinks will work. Then if you need to move or rename the file: open the file from original location and select "Save AS" anywhere you would like to save, in this case hyperlinks of your saved file would work.
Conclusion: relative references to the Excel file in hyperlinks are not automatically updated when externally file is moved or renamed.
So we managed to find out what was the cause of this problem.
Microsoft are currently working on fixing this as stated in the article below, but as a quick fix you simply need to remove Windows Update KB4011051.
https://support.office.com/en-gb/article/Hyperlinks-to-another-Excel-workbook-no-longer-work-after-updating-to-the-August-1-2017-update-KB-4011051-dfe0aa5c-a2ba-41b8-923a-fe0e4556f936
Thanks for the assistance,
Sean

Resources