Moving vba codes to a DLL lazarus / 21-General ---------------------------------------------------------------------- amir.eng · 2022-03-26 08:31 Hello everyone, I have written a macro in Excel with vba codes and may you know vba codes in excel is not secure so that anyone can unlock password protection of a Excel project with free softwares. Recently I found a commericial program (DoneEx VBA Compiler) which converts all vba codes to a Standard DLL and it's very secure, unfortunately I'm not able to but it. I want to know if it's possible to do it via Lazarus ? I mean moving and converting all vba codes to a DLL and then call it in Excel. ---------------------------------------------------------------------- loaded · 2022-03-26 09:24 Hi, I struggled a lot with this issue at the time, but I couldn't do it because Lazarus doesn't have COM+ support. But as a solution, I learned Activex DLL or Activex EXE methods in VB6. Exe is more logical in my opinion because it handles the registration and similar processes by itself. ---------------------------------------------------------------------- amir.eng · 2022-03-26 09:55 We dont need COM or Activex DLL, I guess producing Standard DLL is possible in Lazarus and this type of DLLs can be called easilly with Excel. Honestly, I did it in VB6 before but VB6 is not secure these days and Also ActiveX DLL is not my goal. ---------------------------------------------------------------------- loaded · 2022-03-26 10:51 With the above method, you can use the codes you wrote in Excel almost exactly. Connecting it is even easier than any other method. You can easily connect even with a vbs you wrote in the notepad. Also, Activex Dll is pretty safe, I haven't heard of a known vulnerability. Still, the choice is yours, take it easy. ---------------------------------------------------------------------- marcov · 2022-03-26 16:56 Quote from: loaded on March 26, 2022, 10:24:17 amI struggled a lot with this issue at the time, but I couldn't do it because Lazarus doesn't have COM+ support. What do you exactly miss? ---------------------------------------------------------------------- loaded · 2022-03-26 17:56 Quote from: marcov on March 26, 2022, 05:56:55 pmWhat do you exactly miss? No, there is nothing I miss, and I don't want to go back to those days. It's a bit complicated for me to explain this. With the code below, we can connect to Excel and control it. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Excel:=CreateOleObject('Excel.Application'); Likewise, to control the applications we write, we must create an expression in the window operating system. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Project:=CreateOleObject('Lazarus.Project1');This is exactly what I want to tell you; The ability to create Com+ supported projects is available in Delphi, but unfortunately not in Lazarus. Also, Import Type Library Support in Lazarus is available in VB6 as Reference. Then all the methods in Excel can be accessed very quickly with the Object Browser. The code you write in this way can run smoothly both in Excel "Microsoft Visual Basic for Applications Editor" and in your own application. ---------------------------------------------------------------------- korba812 · 2022-03-26 19:22 You can create COM objects in FPC. The only thing missing is the TLB/IDL editor/compiler. It seems you can use MSIDL compiler for this, but I'm not sure. ---------------------------------------------------------------------- amir.eng · 2022-03-27 09:12 Do you mean it's not possible to produce Standard DLL (Native DLL) in Lazarus ? ---------------------------------------------------------------------- PascalDragon · 2022-03-27 09:20 Quote from: amir.eng on March 27, 2022, 11:12:04 amDo you mean it's not possible to produce Standard DLL (Native DLL) in Lazarus ? Of course it's possible to create a normal, native DLL in Lazarus. You just need to make sure that you use the correct types that VBA expects (e.g. Widestring instead of String or PChar) and the correct calling convention (stdcall). There is however no wizard that will help you convert your VBA code to FPC code. ---------------------------------------------------------------------- amir.eng · 2022-03-27 10:39 I know that there is not a quick way to convert whole of vba code to FPC, then how do work the commercial softwares which create a DLL for a big vba code only in one second ? I believe that the vba code are not converted to another language line by line, and they put all vba code in a DLL as it is. Since there are some libraries like "Autocad Library" in a macro file that  which it's not easy to convert it to another language, but the software can convert to a C++ DLL very easilly. ---------------------------------------------------------------------- BobDog · 2022-03-27 13:05 If it is of any help, here I create a .dll using vbscript. Compile this: file: vbcode.pas Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   library vbcode; {$mode delphi} uses  process;  var g:ansistring=''; kill:integer=1;  procedure savefile(fname:string ;text:ansistring;killflag:integer); label kill;Var T:TextFile;beginif killflag<>0 then goto kill;   AssignFile(T,fname);   {$I-}   try   Rewrite(T);   Writeln(T,text);   finally   CloseFile(T);   {$I+}   end;   kill:  if killflag<>0 then erase(T);end; procedure runscript(filename:ansiString);var s:ansistring='';beginruncommand('cscript.exe /Nologo '+filename,s);writeln(s);End; procedure createscript;beging:=g+ 'Const TriStateTrue = -1 '+chr(10);g:=g+ 'URL = InputBox("Enter (or paste) the URL to extract the Code "&vbcr&vbcr&_'+chr(10);g:=g+ '"Exemple ""https://www.freebasic.net""","Extraction of Source text and html  ", "https://forum.lazarus.freepascal.org/index.php?action=forum")'+chr(10 );g:=g+ 'If URL = "" Then WScript.Quit'+chr(10);g:=g+ 'Titre = "Extraction du Code Source de " & URL'+chr(10);g:=g+ 'Set ie = CreateObject("InternetExplorer.Application")'+chr(10);g:=g+ 'Set objFSO = CreateObject("Scripting.FileSys]"]>Blockedbject")'+chr(10);g:=g+ 'ie.Navigate(URL)'+chr(10);g:=g+ 'ie.Visible=false'+chr(10);g:=g+ 'DO WHILE ie.busy'+chr(10);g:=g+ 'LOOP'+chr(10);g:=g+ 'DataHTML = ie.document.documentElement.innerHTML'+chr(10);g:=g+ 'DataTxt = ie.document.documentElement.innerText'+chr(10);g:=g+ 'strFileHTML = "CodeSourceHTML.txt"'+chr(10);g:=g+ 'strFileTxt = "CodeSourceTxt.txt"'+chr(10);g:=g+ 'Set objHTMLFile = objFSO.OpenTextFile(strFileHTML,2,True, TriStateTrue)'+chr(10);g:=g+ 'objHTMLFile.WriteLine(DataHTML)'+chr(10);g:=g+ 'objHTMLFile.Close'+chr(10);g:=g+ 'Set objTxtFile = objFSO.OpenTextFile(strFileTxt,2,True, TriStateTrue)'+chr(10);g:=g+ 'objTxtFile.WriteLine(DataTxt)'+chr(10);g:=g+ 'objTxtFile.Close'+chr(10);g:=g+ 'ie.Quit'+chr(10);g:=g+ 'Set ie=Nothing'+chr(10);g:=g+ ' Ouvrir(strFileHTML)'+chr(10);g:=g+ ' Ouvrir(strFileTxt)'+chr(10);g:=g+ 'wscript.Quit'+chr(10);g:=g+ 'Function Ouvrir(File)'+chr(10);g:=g+ '    Set ws=CreateObject("wscript.shell")'+chr(10);g:=g+ '    ws.run "Notepad.exe "& File,1,False'+chr(10);g:=g+ 'end Function'+chr(10);end; procedure init;begincreatescript;savefile('script.vbs',g,0) ;runscript('script.vbs');writeln('Press enter to end . . .');readln;savefile('script.vbs','',kill);end; exports  init;  end.   You should now have vbcode.dll This file uses the dll Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  procedure init cdecl external 'vbcode.dll' name 'init'; begininitend. Copy and paste a web page into the box. The dll converts the web page to .txt and .hmtl. It takes a few seconds to do this. Be sure to have the using file and vbcode.dll in the same folder. Tested 64 bit compiler 3.2.2 All coded in Geany ide. ---------------------------------------------------------------------- amir.eng · 2022-03-28 05:50 Thank you for replying. Did you try and call it with Excel ? and if answer is yes, how do you call it ? Could you please send me the Lazarus project ? ---------------------------------------------------------------------- dseligo · 2022-03-28 21:33 Quote from: amir.eng on March 28, 2022, 07:50:03 amThank you for replying. Did you try and call it with Excel ? and if answer is yes, how do you call it ? Could you please send me the Lazarus project ? So I think you have 2 issues: how to run VB code and how to call it from Excel. BobDog showed you how to run VB code. I attached you small project with 3 functions, which creates dll that you can call from Excel (and from LibreOffice as well). In Excel you go to Visual Basic (Alt + F11) and insert new module. There you put this code: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Private Declare PtrSafe Function calc_get Lib "C:\temp\excel_dll\excel_dll.dll" () As IntegerPrivate Declare PtrSafe Function calc_int Lib "C:\temp\excel_dll\excel_dll.dll" (ByVal a As Integer) As IntegerPrivate Declare PtrSafe Function calc_double Lib "C:\temp\excel_dll\excel_dll.dll" (ByVal a As Double) As Double Function cell_get() As Integer  cell_get = calc_getEnd Function Function cell_int(a As Integer) As Integer  cell_int = calc_int(a)End Function Function cell_double(a As Double) As Double  cell_double = calc_double(a)End Function Now you can use it in your cells like this: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i =cell_get()=cell_int(A4)=cell_double(A5) Couple of remarks: You don't need 'Private' in front of 'Declare' in LibreOffice.You have to be carefull how you compile your dll: in 32 or 64 bit. That depends on installation of Excel/LibreOffice.In Excel you have to have full path to dll otherwise it doesn't work after saving/reopening.If you pass strings, they have to be declared as WideStrings. ---------------------------------------------------------------------- Zvoni · 2022-03-29 07:14 Quote from: amir.eng on March 26, 2022, 09:31:24 amHello everyone, I have wrote a macro in Excel with vba codes and may you know vba codes in excel is not secure so that anyone can unlock password protection of a Excel project with free softwares. Recently I found a commericial program (DoneEx VBA Compiler) which converts all vba codes to a Standard DLL and it's very secure, unfortunately I'm not able to but it. I want to know if it's possible to do it via Lazarus ? I mean moving and converting all vba codes to a DLL and then call it in Excel. My first question would be: What's this "password" for? Workbook-Protection, Worksheet-Protection or protecting the VBA-Code? Because for the last two i don't need any external tools (trying to crack the password), and the password is out the window in under one minute.... ---------------------------------------------------------------------- amir.eng · 2022-03-29 08:27 Thank you dseligo for spending time on my project. I did your guidance, but this error appears after calling the function in Excel : "File not found ..." I'm puzzeld that the functions are visible in function list of excel, but it returns "#VALUE" error. Window OS is 64, Compiler is x86_64-win64 ---------------------------------------------------------------------- dseligo · 2022-03-29 09:26 Quote from: amir.eng on March 29, 2022, 10:27:05 amThank you dseligo for spending time on my project. I did your guidance, but this error appears after calling the function in Excel : "File not found ..." I'm puzzeld that the functions are visible in function list of excel, but it returns "#VALUE" error. Window OS is 64, Compiler is x86_64-win64 Is your Excel 64-bit or 32-bit (you can go to Task Manager details page, turn on column Architecture and see it there)? Check target in Lazarus (Project, Project Options, Config and Target): if your Excel is 32-bit then Target OS should be Win32 and Target CPU family i386, and if your Excel is 64-bit then Target OS should be Win64 and Target CPU family x86_64. Also, double check name and path. ---------------------------------------------------------------------- amir.eng · 2022-03-30 21:17 I checked it again, still returns the same error. Excel is 2013-64bit Windows 10- 64bit ---------------------------------------------------------------------- dseligo · 2022-03-31 01:30 I just tried with Excel 2013 64-bit and it's working. We are missing something. I attached screenshots so you can see that it is working at my side. I also attached compiled dll (same code I posted here) and Excel file, if you want to try that. You need only to change drive to F (I tested with E drive). If I can think of something else, I will post it here. ---------------------------------------------------------------------- Jurassic Pork · 2022-03-31 05:48 Hello, amir.eng are you sure that you have an Excel 64 bits ? With a 64 bits Lazarus Dll and Excel 32 bits there is your error. In Attachment a 32 bits Lazarus Dll : Works with an Excel 2016 32 bits. Friendly, J.P ---------------------------------------------------------------------- Zvoni · 2022-03-31 06:47 Not sure if it's your problem, but i noticed something! in your FPC-Lib you use "Integer" for calc_get and calc_int in ObjFpc- Mode and you use "Integer" in your API-Declares in your VBA-Code. That's wrong! ObjFpc-Mode Integer: signed 32-Bit VBA Integer: signed 16 Bit You have to use Long in your VBA-Code. Change the 3 "Integers" in your Declares to Long ---------------------------------------------------------------------- amir.eng · 2022-03-31 07:25 Quote from: dseligo on March 31, 2022, 03:30:10 amI just tried with Excel 2013 64-bit and it's working. We are missing something. I attached screenshots so you can see that it is working at my side. I also attached compiled dll (same code I posted here) and Excel file, if you want to try that. You need only to change drive to F (I tested with E drive). If I can think of something else, I will post it here. I replaced my DLL with your DLL then it works fine !!! I think something is wrong with my DLL, I attahed it, please check it with your Excel. ---------------------------------------------------------------------- dseligo · 2022-03-31 09:13 Quote from: amir.eng on March 31, 2022, 09:25:09 amQuote from: dseligo on March 31, 2022, 03:30:10 amI just tried with Excel 2013 64-bit and it's working. We are missing something. I attached screenshots so you can see that it is working at my side. I also attached compiled dll (same code I posted here) and Excel file, if you want to try that. You need only to change drive to F (I tested with E drive). If I can think of something else, I will post it here. I replaced my DLL with your DLL then it works fine !!! I think something is wrong with my DLL, I attahed it, please check it with your Excel. I didn't check it yet, but judging by the size of it, your dll is 32-bit and not 64-bit (when I was testing 32-bit was around 300kB and 64-bit around 600kB). Can you post screenshot of Project, Project Options, Config and Target screen in Lazarus? ---------------------------------------------------------------------- dseligo · 2022-03-31 09:14 Quote from: Jurassic Pork on March 31, 2022, 07:48:07 amHello, amir.eng are you sure that you have an Excel 64 bits ? With a 64 bits Lazarus Dll and Excel 32 bits there is your error. In Attachment a 32 bits Lazarus Dll : Works with an Excel 2016 32 bits. Friendly, J.P I think it's the other way around: he has 64 bit Excel, but he compiles dll to 32 bits. ---------------------------------------------------------------------- dseligo · 2022-03-31 09:21 Quote from: Zvoni on March 31, 2022, 08:47:32 amNot sure if it's your problem, but i noticed something! in your FPC-Lib you use "Integer" for calc_get and calc_int in ObjFpc- Mode and you use "Integer" in your API-Declares in your VBA-Code. That's wrong! ObjFpc-Mode Integer: signed 32-Bit VBA Integer: signed 16 Bit You have to use Long in your VBA-Code. Change the 3 "Integers" in your Declares to Long You are right here, but it works even if there are declared as integers in 32 and 64 bit Excel and in 64 bit Libreoffice. This is reference from Microsoft about types: https://docs.microsoft.com/en-us/office/client-developer/excel/how-to- access-dlls-in-excel That is what VBA code in Excel should look like: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Private Declare PtrSafe Function calc_get Lib "E:\excel_dll\excel_dll.dll" () As LongPrivate Declare PtrSafe Function calc_int Lib "E:\excel_dll\excel_dll.dll" (ByVal a As Long) As LongPrivate Declare PtrSafe Function calc_double Lib "E:\excel_dll\excel_dll.dll" (ByVal a As Double) As Double Function cell_get() As Long  cell_get = calc_getEnd Function Function cell_int(a As Long) As Long  cell_int = calc_int(a)End Function Function cell_double(a As Double) As Double  cell_double = calc_double(a)End Function Sub test()  MsgBox calc_int(10)End Sub ---------------------------------------------------------------------- dseligo · 2022-03-31 09:30 Quote from: amir.eng on March 31, 2022, 09:25:09 amI replaced my DLL with your DLL then it works fine !!! I think something is wrong with my DLL, I attahed it, please check it with your Excel. I tested your DLL and it is working with 32 bit Excel, so you are compiling for 32 bit and not 64 bit. Check that you 'Config and Target' in Lazarus are as in screenshot I attached, and then recompile your dll. ---------------------------------------------------------------------- Zvoni · 2022-03-31 09:46 Quote from: dseligo on March 31, 2022, 11:21:31 amYou are right here, but it works even if there are declared as integers in 32 and 64 bit Excel and in 64 bit Libreoffice. I might be right, and it might work, but IMO it's VERY GOOD practice to use the correct Types. This time the OP is also the author of the dll/library. The next time it's someone else, and you don't see the source-code for the dll. And now let's return a fully used 32-Bit integer, and cram it into a 16-Bit integer...... BOOM ---------------------------------------------------------------------- amir.eng · 2022-04-01 09:42 Thank you all, it was my fault, it works by changing compiler target to 64. I'm sorry to bother you. At the final, I wanted to combine "BobDog" and  "dseligo" methods to run vba command from DLL, I was trying it with simple command : Range("A1").value = "Test" But Excel hangs and stops working after calling funciton and also Lazarus returns this warning while compiling: Warning: Symbol "RunCommand" is deprecated Could you please take a look at the attached project ? ---------------------------------------------------------------------- amir.eng · 2022-04-06 08:19 Quote from: amir.eng on April 01, 2022, 11:42:27 amThank you all, it was my fault, it works by changing compiler target to 64. I'm sorry to bother you. At the final, I wanted to combine "BobDog" and  "dseligo" methods to run vba command from DLL, I was trying it with simple command : Range("A1").value = "Test" But Excel hangs and stops working after calling funciton and also Lazarus returns this warning while compiling: Warning: Symbol "RunCommand" is deprecated Could you please take a look at the attached project ? Any help? ---------------------------------------------------------------------- marcov · 2022-04-06 11:52 Runcommand with a single commandline is deprecated. Runcommand with exe name and each parameter separately not. ---------------------------------------------------------------------- BobDog · 2022-04-06 12:50 you can use runcommand('cscript.exe',['/Nologo',filename],s); in ~~line 38 in my dll. This will give no warning and I think is is not deprecated yet in that form. ---------------------------------------------------------------------- amir.eng · 2022-04-07 10:05 Quote from: BobDog on April 06, 2022, 02:50:03 pm you can use runcommand('cscript.exe',['/Nologo',filename],s); in ~~line 38 in my dll. This will give no warning and I think is is not deprecated yet in that form. BobDog, Did you test and call it with Excel ? unfortunately I couldn't run vb script by Calling DLL in Excel. Please share files or DLL if you have done it. ---------------------------------------------------------------------- BobDog · 2022-04-07 18:22 Hi amir.eng I don't have Excel, It was only a dll which can run vbscript files. ---------------------------------------------------------------------- Jurassic Pork · 2022-04-08 05:39 Hello, Quote from: amir.eng on March 26, 2022, 10:55:48 amWe dont need COM or Activex DLL, I guess producing Standard DLL is possible in Lazarus and this type of DLLs can be called easilly with Excel. Honestly, I did it in VB6 before but VB6 is not secure these days and Also ActiveX DLL is not my goal. It is not true if you want to execute typical Excel  instruction like Range("A1").value = "Test". In Your DLL you must use EXCEL COM object to execute this kind of instruction. Donex seems the best solution to put and execute VBA code from a DLL. Friendly, J.P ---------------------------------------------------------------------- dseligo · 2022-04-08 09:30 Quote from: Jurassic Pork on April 08, 2022, 07:39:17 amDonex seems the best solution to put and execute VBA code from a DLL. What is 'Donex'? Do you refer to https://doneex.com/? ---------------------------------------------------------------------- Jurassic Pork · 2022-04-08 09:46 Quote from: dseligo on April 08, 2022, 11:30:15 amWhat is 'Donex'? Do you refer to https://doneex.com/? Yes I made a mistake it is DoneEx  And Example code to connect Lazarus to an Excel Instance and write a string in the cell A1 of the ActiveSheet : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses comobj;// ....procedure TForm1.Button1Click(Sender: TObject);  var XL: OLEVariant;begin  try   // try to get Excel Instance opened    XL := GetActiveOleObject('Excel.Application');  except    try      // ShowMessage('Excel not already open create XL Object');      // If no instance of Excel is running, try to Create a new Excel Object      XL := CreateOleObject('Excel.Application');    except      // ShowMessage('Cannot start Excel/Excel not installed ?');      Exit;  end;  end;   XL.ActiveSheet.Range['A1'].Value := 'coucou';end; ---------------------------------------------------------------------- SymbolicFrank · 2022-04-08 10:25 The last time I needed to do something like this, it was enough to put "VB6." in front of the function names. External access to Excel is messy and requires constant updates. ---------------------------------------------------------------------- dseligo · 2022-04-08 10:43 Quote from: SymbolicFrank on April 08, 2022, 12:25:43 pmExternal access to Excel is messy and requires constant updates. My experience too. I have much better experience using FPSpreadSheet (https://wiki.freepascal.org/FPSpreadsheet). If OP still insist using VBA code from Lazarus the way he described, this might be the way: 1. Call dll as shown in post #12 (with regards of using correct types as explained in #23) 2. Running VBA code from dll as shown in post #11 3. Changing Excel's cells as shown in post #34 As we don't know the details of OP's intentions (is this one time convert, does he want to make universal tool to do this, what does VBA code do) this could be very complex task. Depending of what VBA code do, might mean that VBA code can't be run at all as shown in post #11. If it is one time convert, it might be easier to convert VBA code to Pascal and skip step 2. ---------------------------------------------------------------------- dseligo · 2022-04-08 10:45 Quote from: Jurassic Pork on April 08, 2022, 07:39:17 amDonex seems the best solution to put and execute VBA code from a DLL. I just noticed that OP mentions DoneEx in his first post and that he's unable to buy it. ---------------------------------------------------------------------- Thaddy · 2022-04-08 12:23 Quote from: dseligo on April 08, 2022, 12:45:52 pmQuote from: Jurassic Pork on April 08, 2022, 07:39:17 amDonex seems the best solution to put and execute VBA code from a DLL. I just noticed that OP mentions DoneEx in his first post and that he's unable to buy it. That is silly, because VBA - not to be confused with VB - is a scripting language and not a compiled language. It is very simple to store VBA scripts - or even its pseudo code- in a resource only DLL and store it as RT_RCDATA. You do not need any commercial software for that. Just a resource only dll written in e.g. FPC. And indeed you can use createoleobject to subsequenty execute that script from the resource. ---------------------------------------------------------------------- Jurassic Pork · 2022-04-08 13:59 Hello,  Quote from: Thaddy on April 08, 2022, 02:23:39 pmThat is silly, because VBA - not to be confused with VB - is a scripting language and not a compiled language. It is very simple to store VBA scripts - or even its pseudo code- in a resource only DLL and store it as RT_RCDATA. You do not need any commercial software for that. Just a resource only dll written in e.g. FPC. And indeed you can use createoleobject to subsequenty execute that script from the resource. DoneEx doesn't put the vba code in a dll : it builds a portable exe : QuoteDoneEx XCell Compiler is the unique compiler for MS Excel XLS files which allows you to turn XLS workbook logic into portable EXE application (which require MS Excel to run) with hidden formulas and attach XLA Add-Ins to EXE. It also allows you to promote your company name and/or trade mark by attaching your own image as splash screen in final EXE package VBA code protection : VBA copy protection blocks access to the VBA project (as it makes VBA project unviewable), and hides the VBA code, thereby disabling VBA debug mode. By applying the VBA code modification options, such as ‘Obfuscation’ and ‘Literals Removing’,  you will get modified VBA code, which will not work outside of the compiled application. i don't work for DoneEx  Friendly, J.P ---------------------------------------------------------------------- Thaddy · 2022-04-08 14:16 Well, I will build a simple example in the weekend. (Did that already for KOL back in the early 20's). It is quite easy. ---------------------------------------------------------------------- BobDog · 2022-04-08 21:07 Are you using vba to call the dll? for vbcode.dll In freebasic (which is not a million miles removed from vb), I call the dll thus: declare sub init lib "vbcode" alias "init" freebasic won't accept a path under lib, i.e. the dll must be in the same folder as the executable using it. Also freebasic doesn't want the .dll extension in the name. try various things, maybe declare sub init cdecl lib "vbcode" alias "init" or make the init uppercase. ---------------------------------------------------------------------- amir.eng · 2022-04-09 00:13 Quote from: Jurassic Pork on April 08, 2022, 11:46:37 amQuote from: dseligo on April 08, 2022, 11:30:15 amWhat is 'Donex'? Do you refer to https://doneex.com/? Yes I made a mistake it is DoneEx  And Example code to connect Lazarus to an Excel Instance and write a string in the cell A1 of the ActiveSheet :  I'm working with FPS for first time and it seems great !! Your sample code works fine when excel is open, but it gives error during CreateOleObject Excel (when Excel application is not open) : "Access violation" ---------------------------------------------------------------------- Jurassic Pork · 2022-04-09 09:52 Hello, Quote from: amir.eng on April 09, 2022, 02:13:54 amYour sample code works fine when excel is open, but it gives error during CreateOleObject Excel (when Excel application is not open) : "Access violation" try this : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses comobj;// ...procedure TForm1.Button1Click(Sender: TObject);  var XL: OLEVariant;  begin    try   // try to get Excel Instance opened      XL := GetActiveOleObject('Excel.Application');    except      Exit;  end;    try     XL.ActiveSheet.Range['A1'].Value := 'coucou';    finally    end;  end;   there is no sense to use createOleObject("Excel.application")    here, because in your case , you want to use this code in a dll  from an Excel workbook opened. Friendly, J.P ---------------------------------------------------------------------- amir.eng · 2022-04-09 10:51 Quote from: Jurassic Pork on April 09, 2022, 11:52:32 amHello, Quote from: amir.eng on April 09, 2022, 02:13:54 amYour sample code works fine when excel is open, but it gives error during CreateOleObject Excel (when Excel application is not open) : "Access violation" try this : there is no sense to use createOleObject("Excel.application")    here, because in your case , you want to use this code in a dll  from an Excel workbook opened. Friendly, J.P You're right, I don't need it right now, but I just wanted to learn how to create Excel application,Worbook, and Worksheet with Lazarus. It may be needed in the future. Just very simple example as same prior code. Thanks in advance. ---------------------------------------------------------------------- amir.eng · 2022-04-19 07:09 Quote from: Thaddy on April 08, 2022, 04:16:37 pmWell, I will build a simple example in the weekend. (Did that already for KOL back in the early 20's). It is quite easy. I'm looking forward to your reply, I think it's a great idea to run vb script by FPS.