-1

I've been working with macros on VBA for a while, and there's some information on them that I want to hide. As excel is a very unsafe language, I've come with the idea of creating an .exe file of the compiled script to avoid people from accessing my code. I've been looking for the way to do this with Visual Studio, but can't get the answer. Can someone show me how to do this? Many thanks in advance :)

Community
  • 1
  • 1
  • I dont know if this solves your problem but maybe you can use a plugin? See [Create Excel 2007 vsto add in](http://www.clear-lines.com/blog/post/create-excel-2007-vsto-add-in-getting-started.aspx) – Stefan Nov 07 '16 at 14:49
  • @Stefan Thank you for your answer. I've done some research starting from your link and I think I will find it useful. I haven't put it under test, but that's the starting point that I was looking for. =D – Martin Router King Nov 11 '16 at 08:19
  • Ok, glad to hear that. If you find what are you looking for, share your knowledge. ;) – Stefan Nov 11 '16 at 16:18
  • I appreciate you support, but I'm afraid to say that it didn't help in the end... Even though I still have the same problem, I can tell my progress... I'm trying to find a way to create a .DLL file of my VBA script with Visual Studio. I'm completelly new into VS so... It's not being easy... – Martin Router King Nov 16 '16 at 09:36

2 Answers2

0

I dont think that you can create EXEs/DLLs by using vba. EXEs/DLLs are compiled assemblies, therefore you need a programming language/environment that can be compiled. Compiled means "pre-translated to machine language". VBA is just an interpreted language, that means that it will be translated on the fly in the VBA environment. I think you have to use C#, C++ etc. to do this. For further infromation please see:

Create a DLL using VBA editor

http://www.geeksengine.com/article/create-dll.html

https://msdn.microsoft.com/en-us/library/dt232c9t(VS.80).aspx

You can lock and hide your VBA code without creating a DLL:

http://www.excel-easy.com/vba/examples/protect-macro.html

http://www.ozgrid.com/VBA/protect-vba-code.htm

Best way to protect Excel VBA code?

But I am not sure if that solves your problem: You say, that excel VBA seems to be an unsafe language. I am not sure if I understand what you mean. If you just want to hide the contents of the script, see above. Up to now this will protect your code better than in further versions of excel. But I think there is still a way to crack that, e. g. Brute Force attack etc. Usually that are enhanced methods but if you want to be sure you (or better an experienced programmer have to create a programm (exe) for that. If secure means something different (why do you want to hide your code?) than let me know, maybe there is a other way to achieve what you want to do.

Community
  • 1
  • 1
Stefan
  • 1,253
  • 2
  • 12
  • 36
  • Thank you very much for your answer, really appreciate it. I will have a further look into the links you have sent to me, I don't have much time right now... What I meant for unsafe is that as you could have notice, these methods of protecting vba code with passwords are extremelly easy to break into. I am currently working importing data from the database, so the database IP:port and ID and PASS are on the script, which is completelly unacceptable. It is for internal use in the business, but you know... better safe than sorry... – Martin Router King Nov 16 '16 at 14:12
  • I understand the differences between compiled and interpreted languages... but, all my work until now it's been done in VBA so... changing the way of programming the code would be realy tedious... That's why I am thinking about the possibility of creating a .DLL in the part of the connection to the database, this way all the functionalities will be OK while UserID and PASSWORD are safe in the compiled part. I hope I explained my issue well enough so that you can understand me. As I said, I will have a look into the links you sent me, I hope I can get a good result. I will let you know if so! – Martin Router King Nov 16 '16 at 14:16
  • Yes, sure, I know what you mean. I did not develop own dlls in vba up to now. But as far as I understood the links it should be possible to just move a part of your functionality. A possibility could be that you create a proxy-like dll. I found the following post which could help you [http://stackoverflow.com/questions/3217014/how-to-securely-store-connection-string-details-in-vba](http://stackoverflow.com/questions/3217014/how-to-securely-store-connection-string-details-in-vba) – Stefan Nov 17 '16 at 13:17
  • Okay Stefan... You are a God! That link worked beautifully for me! I had to adapt some things, but the functionality is perfect! I will post the code as an answer so that other's can make use of it, in case they have the same issue. – Martin Router King Nov 18 '16 at 13:38
  • Thanks for the flowers! :) Glad to hear that. Yes, that would be great! :) – Stefan Nov 19 '16 at 12:11
0
using ADODB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace HiddenConnectionString
{
[InterfaceType(ComInterfaceType.InterfaceIsDual),
Guid("2FCEF713-CD2E-4ACB-A9CE-E57E7F51E72E")]
public interface IMyServer
{
    Connection GetConnection();
    void Shutdown();
}

[ClassInterface(ClassInterfaceType.None)]
[Guid("57BBEC44-C6E6-4E14-989A-B6DB7CF6FBEB")]
public class MyServer : IMyServer
{
    private Connection cn;

    private string cnStr = "Provider=MSDAORA.1;Password=YourPass;User ID=YourID;Data Source=YourServer";
    public MyServer()
    {

    }

    public Connection GetConnection()
    {
        cn = new Connection();
        cn.ConnectionString = cnStr;
        cn.Open();
        return cn;
    }

    public void Shutdown()
    {
        cn.Close();
    }
}
}

You might get this error... It is because of the InterfaceType Guid

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) Check this link for the solution:

https://social.msdn.microsoft.com/Forums/en-US/26accc30-9cfb-4d86-9c27-780f51929ecb/access-is-denied-exception-from-hresult-0x80070005-eaccessdenied?forum=vsreportcontrols

This is the code but I would visit the link that Stefan suggested.