How to properly write Excel macros for other people - excel

I recently started writing VBA macros, even though I never learned VBA. So basically I am translating my python knowledge to VBA, which works most of the time.
However I want to improve my coding skills, especially when it comes to working with other people.
Usually I am writing a Macro and then install it on the computer of my colleagues, so that they can use it as well. But the way we develope the macro is currently a try-and-error approach, so I have to edit the code quite often. Currently I just copy paste the new lines into an Email and the person has to exchange that line by themselves.
My Question: How do professionals handle updating VBA Macros? Is there something like "patches"? Or can you have a shared "Personal.xlsb", so that all changes are automatically updated for everyone else as well? I am the only person editing the code anyway, the others just use it.
I googled a lot and also looked through stackoverflow, but only found this: How to write a patch to Excel VBA codes? where the answer basically was, that you can't write patches. But there surely must be a way, to update my macros in a better way, right?
Thanks in advance!

Related

How can I convert my Excel VBA Macros to EXE File? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have prepared lots of Excel based Tools using excel macros. In these Excel Sheets user normally browses Excel files or inputs data as guided by the tool and then runs my macros to generate a desired output. Everything is working fine.
However, instead of distributing these tools as Excel sheets, can I convert my codes to a exe file and distribute it to users who can run it there?
I searched a lot on Excel to exe related threads but didn't get a satisfying answer hence thought of starting a new thread.
This answer might not be satisfying too but the fact is that Excel is no programming tool to produce stand alone applications (exe).
Therefore you need to re-write your project using a real programming language (and tool) like VB.NET or C#. VBA (Visual Basic for Applications) is meant to run in applications as its name says (like Excel or other Office applications) but not stand alone.
There is no way of just converting the code (by pressing a button or something) you will need to re-write the whole project/tool completely (by hand) in another programming language if you plan to use your application stand alone (exe) without Excel.
Please note that even if VBA and VB.NET use similar syntax you cannot just copy the code. These are 2 completely different languages and the code needs to be re-written. Even if the result would look similar it is not the same.
Your solution is not the answer to your need. What you actually want is an Add-In file that you can distribute to your users. This file extends Excel and gives users access to your tools, but can be password protected and hidden so users can't mess with it . At it's simplest it's just a case of saving the workbook containing your code as a file of type Add-in, but you do need to rewrite your code to make explicit which workbook you are working with, since ThisWorkbook in your code is the add-in, and ActiveWorkbook is the file that the user has open while using your addin. You will also need to develop menus to give users access to your tools, since they can't see the add-in.
You can only do that if you do it outside excel, write a program in a Windows development tool which is able to communicate between applications. You can use many Microsoft development platforms for this, f.e. C#.
What you want to do is start a process to interfere with another process.
How to do it depends a lot on the targetted windows-version. It is not an easy subject, and I don't know if you really want to go this way. But if you do, Google on inter-process communication and Windows.
This is a nice overview article:
https://learn.microsoft.com/en-us/windows/desktop/ipc/interprocess-communications

Is it possible to use pull information from the web using data from excel?

I have an excel sheet I've received from someone with information about their personal library recently, and they've asked me to add the library of congress number to every book on the sheet. There's thousands of books on this thing, and it would take forever to search the library of congress website and copy-paste everything on here. Is there a built-in function or a way to have a column search the website for each book and copy the appropriate number?
Err... No.
This specific functionality (searching the library of congress) is so specific, that it makes no sense for Microsoft to add it to Excel. There would be probably 3 people in total that would EVER use it.
A more generic functionality (take an arbitrary webpage and look for some arbitrary information in it) would on the other hand be too vague. Either it would be useless or it would need to have a bazillion parameters to get it to do what you need to. And you'd need to spend months trying to configure it just right.
Actually, Excel does kinda offer this generic functionality - it's called the VBA. You can write custom programs there that can do pretty much anything under the sun. The downside - it's programming. If you know what you're doing, you can probably get it done in a couple of days, maybe a week. If you don't know... good luck. You'll need it!

Best way to protect Excel VBA code?

I've put together a simple Excel database that performs a few macro functions and I need to distribute this database to a few people - but they cannot see how the macro function actually works (stupid rules I have to follow!). What is the best way to achieve this?
I've done a bit of research and I found two ways:
Password protect the VBA project; but this is apparently very easy to break using readily available tools online (it would be in the best interest to the people I'm sending this to find out how the macros and functions work; so I'm almost 100% sure they will try to get into it.. hence a password protection seems inadequate.
Move to a fully compiled language like C++; my skills are very limited to VBA on Excel and Access so this being the ideal solution; isn't a solution for me :(
Are there any other ways? I thought of having a 'master excel document' with all the macros in that and then send 'children' databases to the end users and have the 'children' databases connect to the 'master' - is something like this possible? By hosting the master online or even sending the end users the master but making it completely inaccessible unless accessed by the 'children' databases?
You can create Automation Add In.
An Automation Add In provides several advantages
Execution Speed : An Automation Add In written in VB6 is compiled to
native machine code which runs much faster than the interpreted VBA
languange.
Security : Unlike an XLA add in, you never distribute the source code to the end users. If your code has proprietary information or
intellectual property value, that remains safely protected on your
own computer. It is never distributed to the user. Your code can
never be compromised.
http://www.cpearson.com/excel/automationaddins.aspx
There aren’t too many ways to protect your Excel VBA code reliably.
You can try to use passwords or VBA obfuscators, but all of that protection is limited. Passwords are easy to break, and obfuscated VBA code can still be traced back and recovered.
The other answer to this question mentions using VB6, but that limits your code to 32bit Excel. Also VB6 can be decompiled by VB decompiler.
Converting your code to a compiled language is indeed the best way to protect your VBA code, but be warned that in this case not all code is created equal.
Converting your code to VBA.NET is a flawed solution because the compiled code of .NET assembly can be converted back into the original source code.
Converting your VBA code to C or C++ is the most effective form of protection, but this takes a lot of experience and effort since C/C++ and VBA are very different languages.
I would suggest you have a look at a tool called VBA Compiler for Excel (https://vbacompiler.com/how-to-compile/). It compiles your Excel VBA code into a DLL file with a click. You do not need any knowledge of C or C++ languages to use it.
If you're still looking for a good way to protect your Excel VBA code from copying or tampering, then you should consider the Excel VBA compiler of XLS Padlock.
Because XLS Padlock offers an integrated VBA compiler that can compile your VBA code into binary code, making it completely secure and inaccessible to others.
it's really binary code and not simple obfuscation.
You open the VBA compiler of XLS Padlock, move some vital parts of your existing VBA code into it (subs or functions) and it compiles live. You can then invoke this compiled code directly from your normal VBA project using dedicated functions.
It's like having several modules, except that some modules are compiled into bytecode and thus secure.
No need to learn a new language C or C++ or VB, nor COM add-ins.
Plus, XLS Padlock can wrap your Excel workbook into a secure shell application, which you can then distribute and even sell to your customers.
It does not create DLL files that must then be distributed among your workbook files (imagine if your other non-tech users lose the DLL or don't know what it is), the software compiles spreadsheets + compiled code into a single EXE file.
It is even possible to add licensing features, online activation if you want to sell your workbooks or control who uses them, while keepking your VBA code secret.

Easiest way to allow others to install an Excel (2011) macro?

I wrote a macro from scratch but would like to have non-technical people install/run it at ease. I'm unfortunately not onsite so I was hoping to defer the hassle to myself and offer them a one-(or few)-click solution. Any advice?
This Stack Overflow link seemed to be one of the better solutions, and this is still probably too complicated for my clients.
Well, for a one click solution, you are going to want to create an add-in and then an installer. This guide covers this pretty well in depth:
http://msdn.microsoft.com/en-us/library/ff937654.aspx#Create
If you don't want to do that, then the easiest way is to just copy/paste the macro (if it is not too complex) into each user's workbook or personal.xls if it needs to be used in multiple workbooks.

How to make a library I can access in VBA in Excel

I am doing a lot of similar tasks among some VBA scripts I am writing and would like to develop a library (a bunch of convenience functions using the typelib I'm working with) which I can call from all my various scripts. I am new to the VBA world and do not know how this is done and have had a surprisingly hard time trying to figure it out.
I think what I was looking for is an Add-In. Thanks everyone for your information.
Does this example help? It appears to also have a fix to a common issue when setting this up - You didn't mention which version of office - But 2003 is mentioned in that thread, so should be the fairly straight forward common case.
http://socko.wordpress.com/2008/06/01/vba-code-library/
Another option you have though it depends on the nature of your functions, is to create a COM object that you can call from your VBA scripts.
You can easily create a COM object using many languages including Delphi and VB (old style) it is also possible in .NET though a little more involved. You can then do your calculations in your COM object and even pass in the excel worksheet etc you wish to manipulate if required.
Depending on the nature of your functions this may or may not be useful.
You will need to use VB to do this. With Microsoft plug-ins to VB, you can manipulate Excel files without even opening them, much like you do now. The code will be very similar once you have the file open.
I would transfer all my code to VB and after its working like you have your VBA macros start making libraries out of the common stuff.
Lots of work, but if you really are doing a lot of this stuff, it will be great in the long run. (Job security too ;)
Check the comments here
http://www.dailydoseofexcel.com/archives/2004/10/15/code-libraries/

Resources