Visual Studio Macros Editor - vba

Is there a way to change the macro editor from this default one:
It feels like such a downgrade from Visual Studio 2010. Can I configure Office to use that instead?

no there is no way to my knowledge, VS.NET does not support VBA.
what you can do if you are creating a new word or excel file is create a managed office solution, having installed the VSTO 2010 (Visual Studio Tools for Office) you are able to create managed documents which are handled inside VS 2010 and the automation language is not VBA anymore but C# or VB.NET instead.
this is a viable solution for new files, for legacy files either you convert them if they are small or you keep old VBA code and old VBA editor as in your picture.
Mark I wish MS made a tool to convert from the old format to the new one! :(

There are things you can do to improve it:
Tools > Options > Editor :
Uncheck "Auto Syntax Check"
Tools > Options > Edit Format:
Customize the colors and font
Install the VBA Rubberduck:
http://rubberduckvba.com/
The RubberDuck does auto-indent for you. It also helps you with "unit testing, source control, from code inspections, and refactorings"

Related

Prevent auto-formatting in Visual Basic

Using Visual Studio 2019. In Options > Text Editor > C# > Code Style > Formatting untick all the Automatically format options. Great! Now when I type or paste something into the editor it stays there.
How do I prevent automatic formatting in Visual Basic? Wasn't able to find the options.
(PS: We have tonnes of legacy VB code. This will be upgraded to C# when an opportunity arises.)
(Converting my comment to an answer):
It's under Options > Text Editor > Basic > Advanced > Pretty listing (reformatting) of code - and there's some other options there too that might interest you.

Office365 Excel access to the Tools -> References menu for RegExp library

This might sound like a simple question but I'm creating a macro in VBA that uses regular expressions. It turns out VBA doesn't inherently support regex and I need to add a reference to 'Microsoft VBScript Regular Expressions 5.5' to gain access to regex functions in Excel.
All my searching online tells me you need to go to Tools -> References menu to add/remove references that can be used in VBA.
The Tools -> References menu in Excel as obtained from Google
For the life of me I can't see where the Tools -> References menu is in my Excel. I've enabled the Developers tab and it's not there.
This is what I see
If it helps, I'm using Excel on Office 365 (which Wikipedia tells me is Office 2016) on a Mac. Please help me find how I can access the References menu in Excel (whether or not it can be accessed via Tools -> Menu or some other way). Thanks.
You need to open the Visual Basic editor. On the ribbon in Excel, select Developer, then Visual Basic. This will open the VBA interface in a separate window. On this new window, you should see the Tools -> References option.
You need to open the Visual Basic (for applications) Editor, or VBE. On the Developers tab, look for "Visual Basic". It should be the left-most item.
Or, you can press Alt-F11.
The VBE is where you'll find the Tools menu, and the References submenu.

Is it possible to enable syntax highlighting for Microsoft Visual Basic?

I am working on a very old project which needs to be updated. Because the program needs to be backwards compatible, the changes need to be made in this older IDE.
There is no built in syntax highlighting that I see. Is there a plugin or menu that I have missed?
Within VB Editor, go to Options then Editor Format and adjust colours.
There are also some 3rd party softwares out there that will enable you to edit your code with syntax highlighting.
UltraEdit Visual Basic Editor

Is it possible to write Excel VBA Code in Visual Studio

Is there a way to write VBA Code in Visual Studio. If not is there any other alternatives?
The best you can do is bend the office Visual Basic Editor (VBE) tool to your liking. If you stay in it's native environment you get the full power of error detection, Intellisense, live code running, etc.
My tips...
In the VBE go to Tools > Options > Editor tab.
Turn off 'Auto Syntax Check'. You still get code highlighted errors but no annoying popups.
Go to the Editor Format tab and change the Font to Consolas (Western), Size 11.
For code indenting install the awesome, free, Code Manager. It adds some sick keyboard shortcuts.
Make the Edit toolbar easily accessible for code commenting/uncommenting.
Use Rubberduck to add unit testing, source control, code inspections and refactoring functionality.
With those simple changes you end up with a half way decent, useful, and keyboard friendly environment to write your visually appealing code. :-D
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 following MSDN page covers both developing with VBA and VSTO.
Excel for developers
You could also use the interop features of VBA to consume a (COM) object written in Visual Studio from your VBA code.
I've been looking for an answer to this question myself.
Best I've found myself is the option of exporting a Module ect from Excel with the code you've already written (or blank) and load that up in the Visual Studio Environment.
It doesn't offer much, but the highlighted text and auto indenting is nice and makes it much easier to read compared to the standard VBA environment.
Then once you're done just import it back into Excel.
There is a VSCode extension to do this.
It allows you to write code in VSCode and export it to Excel.
This extension is very useful when you develop in VBA.
Here's the link to download the XVBA extension
Edit :
As Peter Macej said in comment, this solution only works for Visual Studio Code not for Visual Studio
You can certainly add and edit a VBA file (.vb) in your Visual Studio solution, but the intellisense will be worthless/screwed up.
This extension for VScode would probably provide a much better experience: https://marketplace.visualstudio.com/items?itemName=spences10.VBA
If your goal is have your VBA code exposed to source control so you can track changes, then it's still worth it to include in your Visual Studio solution, but just store that VBA code in a plain text file and then use the Excel interop to load it into the appropriate module within the excel workbook, e.g.:
xlWorkbook.VBProject.VBComponents["ThisWorkbook"].CodeModule.AddFromFile(#"C:\PathToYour\VBAcode.txt");
And there are other methods to delete/replace code lines, etc....
You can try xlWings package for python and use it with VS Code https://youtu.be/xoO-Fx0fTpM

Office 2007/2010 Custom Ribbon Export

I've gone through the tutorials on how to create a custom ribbon with Visual Studio. I see that you can export your Ribbon XML. Is it possible to utilize this ribbon with another document? Do you have to use Visual Studio at that point or is there a way to embed the custom ribbons into another document? (without VSTO)
Ok... After doing more and more digging. I've come up with some answers.
You do NOT need to do a full-blown VSTO (Visual Studio 2008/2010) Office document to modify the Ribbon (Fluent UI). You can create custom XML (which is real easy if you use the Ribbon designer in Visual Studio) and inject it into the Office document. To make it real simple there is a tool out there that does this for you: Custom UI Editor for Microsoft Office.
Also there are great references on this site: http://www.rondebruin.nl/ for instance: http://www.rondebruin.nl/ribbonx20072010.htm