Add-in macro conflict Excel - excel

Initially I have 1 function: CusFun in an Add-in1
I copy all code in Add-in1 into module in Excel file, save file 1.xlsm
I open 1.xlsm to work, now I have 2 functions CusFun
I changed the name (and only the name) of the functions in macro in module1 in 1.xlsm as CusFun_Port
Now I have 2 UDF: CusFun and CusFun_Port when I work with 1.xlsm
But CusFun_Port (all of them) always return blank while CusFun work normally.
Why use macro-enabled file instead of add-in? Because I need to send the file to many users back and forth. I initially thought only I use them, using add-in save me the trouble of clicking "Enable content". With add-in, every computer use it must install it. And when the file is sent to another computer, all the custom functions in the file must be re-targeted to that computer's add-in location. My users are not proficient in any of those tasks. And those tasks takes far more time than clicking "Enable content".
What can I do to make sure that both functions in add-in and file-specific macro work?

Finally, I found it. Because I change only the name at the top of the function, it doesn't work. Because all of them are recursive, the function's name inside did not change, hence it doesn't work. There is no conflict here.

Related

How to make self-modify Excel workbook in shared folder with read-only permissions?

I made a workbook with VBA which is stored at shared folder of my employer. Employees can open this folder and workbook, but only as read-only.
User at this workbook works with several macros and I need to count number of starts these macros and store this data somewhere. In the best way, it will be stored in the workbook itself. But they do not have rights to modify the workbook, so they cannot save it even if I will try do it automatically as part of macro.
So what I need, is to find a way, how to make this workbook self editing (or auto-saving).
I found two possible ways, but they do not work at this scenario:
Because the file is opened just in read-only mode, I cannot save it directly. I even cannot use save-as and rewrite that file, because I haven't rights to editing it in that folder.
I found a way, where is new document in PC repository and the workbook saves data in that file and this file must be saved somewhere, where it could be editable. But I do not know networking enough to find a save place where I will make this file and even more, I am not sure, how will HQ looks at this type of activity.
I would prefer to count it in the file, but from MS support I get, that I cannot save it, just rewrite, which is impossible if I have not rights for that. So my question is, is there any save way how to count it or store data somewhere else?
As far as I know, without getting write-permissions fixed for your users, it can't be done. You should work with your network administrator to explain your requirements for the users.
Alternatively, you need to find a place where every user DOES have write-access, then design the script to save-as to that location. It all comes down to permissions.

How to change the "fullpath" property of References in VBA (Tools -> Refences)?

I'm sure that there are different ways to phrase this question, but that is the end result that I want to achieve.
So, I have a setup where code is written in C# and added as functions to Excel. It relies on having a specific .tlb file in the Tools->References that can be found in the VBA window.
While I was testing this, the .tlb file (and the rest of them) was on my local drive, but now that the project is working, I need to transfer it to a network drive. The problem is that I can't find any way to change the actual file (or filepath) that is being referenced - it's always looking at my local path.
I've tried a few things:
Followed the steps listed here https://support.microsoft.com/en-us/help/308340/how-to-check-and-remove-incorrect-project-references-in-the-visual-bas
Tried several VBA codes using the .References.Remove expression. This does not actually remove the reference from the list, it only unticks it.
I've tried to remove the file from my local drive (causing an Excel error that a reference has been moved, deleted or renamed - good) and then add a reference from the new location that I want. This resulted in one of two things:
1) If I try to add it manually - nothing happens, the existing reference remains unticked and nothing new is added (that I know of).
2) If I try to do it via .References.AddFromFile "filepath" expression it ticks the reference, if it was unticked (this does not make the external formulas work), or an error that a reference with such a name already exists, if it was ticked.
Recompile on the network drive with the following silly way.
Open the VBA editor
Go into each module
Insert a line (doesn't matter what you write)
Press ENTER
Remove the line that you've inserted
When finished, in the menu click Debug \ Compile
Source: by Andreas Killer
https://answers.microsoft.com/en-us/msoffice/forum/all/ms-excel-error-cannot-run-the-macro-the-macros-may/3f3106b2-ae60-4d21-ac94-67e54e605922

How to have Excel to run VBA code saved in a text file?

Instead of having the VBA code saved in a module inside the Excel file, I would like to have the code saved in a text file, for example module1.vba. In Excel, module1.vba would be loaded or imported and run as it was a normal module.
Is that possible? How to do that?
In Excel, in the VBA editor, there is the option Insert > File... in the menu that does sort of what I want, but I don't know how to automate that with a minimal VBA code to load the real code saved as text.
Reason for this is to allow code revision control using text based applications like git.
--- edit ---
This answer shows a good alternative work around. However I'm still not too happy in duplicating things.
You can easily import a VBA file using a simple one-liner:
Application.VBE.ActiveVBProject.VBComponents.Import "C:\Path\To\File.bas"
This works with files exported from the VBA IDE, which include information like module name and other properties that can be configured on a per-module basis.
You need to enable Trust access to the VBA project object model for this to work. You can find that in the trust center settings, under Macro Settings.

How to call macros using azure api

I have an excel file containing around 100K rows in onedrive. This file contains some macros. I want to run these macros using api.I want to pass these macro functions as parameters.
For example
https://graph.microsoft.com/beta/me/drive/root:/book1.xlsx:/workbook/tables/{id|name}
Here, I want to call macros function in place tables/{id|name}
Any way to do this?
Thanks
To be able to run an Excel macro, you need a running Excel instance that opens the file containing the macro and runs the code. There is no way around this I'm afraid.
So you need a machine - physical or virtual - where Excel is installed. Then you can have a script open the Excel file there and run the macros.
If you are working in a cloud environment or on a web server for example, you would be better off rewriting the code in another language, independent of Excel. (Trust me, I've been there, done that.)

Matlab: open files 'outside Matlab' by default

I'm looking for a way to have Excel files in my Matlab folder open 'outside Matlab' (i.e., by MS Excel in most cases) directly by double-clicking the file, rather than right-clicking and selecting 'Open Outside Matlab'.
The .xls files reader built in Matlab can be terribly slow for large files, and an unwanted double-click on a file can cost quite some time in which Matlab is unresponsive.
Thanks.
When you click something in the Current Folder tab, it's actually running the open command, which itself calls finfo to determine what it means by "open" for a given extension. You can see this by creating a breakpoint in open.m directly after the line [~, openAction] = finfo(fullpath); and double clicking - when it hits the breakpoint you'll see it returns openAction as uiimport.
In theory, you can create custom methods for extensions by creating on the path a function openabc where abc is the extension, which should be returned as the openAction.
However, if I look at my finfo.m it first searches for said functions and then regardless of whether or not it finds them if there is an inbuilt method it overwrites them with the standard behaviour. There's even a comment:
% this setup will not allow users to override the default EXTread behavior
If you are willing to muck about in the inbuilts, you may be able to do it like this (backup first! - this could affect other things). I did it temporarily by shadowing the existing finfo like this:
edit finfo.m (Now save a copy to the current folder)
Add these lines after the loop that defines the openAction (in my version, around line 85):
if any(strcmp(['.' ext], matlab.io.internal.xlsreadSupportedExtensions))
openAction = 'winopen';
end
From the folder containing your edited finfo.m, type which finfo -all. You should see two copies, the MATLAB one labelled as shadowed. Opening something from the current folder window should now open Excel externally.
I don't believe there's any straightforward way to do that. It's built in to MATLAB that Excel files will open in the import tool when you double click on them, and there's no way to change that.
You might be able to get around it by changing the file extension on your Excel files to something other than .xls or .xlsx. That would stop MATLAB from opening it in the import tool. Then in Windows, you could associate the new file extension with Excel.

Resources