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.
Related
I am using VB.Net 2015 edition and it's coder menu not showing. How to add that?
Image Of Menu in Coder:
Tools > Options from the main menu. Text Editor > Basic > General and check the 'Navigation bar' box. ALWAYS look in the IDE options when you want to manipulate the IDE. Yes, there's a lot in there, but that's why you should have a look through it BEFORE you need to use it: so that you have a fair idea of what's available. Anything related to the code editor window specifically is under the Text Editor section.
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 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
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"
In Visual Studio when working in VB.Net, it automatically creates lines/regions around methods etc.
How can this be turned off somewhere in the options?
If you open Tools ==> Options, and select Text Editor, there is a "Basic" section for Visual Basic. This option is on the "VB Specific" sub-section. Unselect "Show procedure line separators".
Using Visual Studio 2017 and above
For C# and Basic
Open Tools > Options or press Alt + T + O
At the top of the list search for "Show procedure line separators"
select Advanced
In group box Outlining
Uncheck "Show procedure line separators"
This is known as "Outlining Mode" and can be disabled by doing the following
Tools -> Options -> Text Editor
Navigate to the Basic -> VB Specific sub category
Uncheck "Enable outlining mode"
For anyone that comes across this and is using Visual Studio 2012. Those lines are off by default. If you want the lines back then you need to:
Tools -> Options -> Text Editor
Navigate to the Basic -> VB Specific sub category
Uncheck "Enable outlining mode"
Yes, these are the same steps that JaredPar explained to turn the lines off. However, it's completely backwards in 2012 and unchecking this option will bring the lines back.
Way to go Microsoft!
The menu sequence is a bit different for VS2015.
Tools -> Options -> Text Editor -> Basic -> Advanced
Uncheck "Show procedure line separators."