OK, so I have to learn VBA in my new line of work as we use Excel to more or less anything. The built-in VBA editor in Excel drives me absolutely bonkers - it feels like it's not made for writing code in an efficient way.
I have been using Sublime Text for all coding purposes recent years. There's a plug-in for writing VBA vbScript in Sublime, but I don't understand how to link my Sublime written code to my Excel documents. Say I try to run the following file
Sub test()
Debug.Print "Hello, World"
End Sub
from Sublime Text, I get the following out from the console [Finished in 0.1s]
, but no printout.
My question is this: does anyone have a solution for how to run VBA in Excel from Sublime Text or Notepad++? I'm still a massive noob in VBA, therefore it would be nice to be able to actually see the effects on the Excel Workbook next to testing the code.
Visual Basic for Applications (VBA) is an implementation of Microsoft's event-driven programming language Visual Basic 6, which was declared legacy in 2008, and is an associated integrated development environment (IDE).
VBA code for Excel can only be written inside Excel using the VBA IDE. VBA projects are stored as part of the Excel file and cannot be loaded into Visual Studio. However, you can write VSTO (Visual Studio Tools for Office) managed add-ins for Excel using Visual Studio.
The problem with VBA code and writing it in Sublime is that VBA is embedded into Excel, so you cannot just build the macros you write in Sublime
*.bas
and *.cls
files and edit them directly in Sublime Text. For that you can use macros from Ron De Bruin website. Just copy the code into seperate module and it will export all code you have in the currect project into seperate files, which you can edit in Sublime Text. After you make changes in Sublime just import all files back again into VBA editor with the macro. You might want to change the VBA code slightly as well by commenting out
If wkbSource.VBProject.Protection = 1 Then
MsgBox "The VBA in this workbook is protected," & _
"not possible to export the code"
Exit Sub
End If
... otherwise it won't import back to the same spreadsheet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With