Dear Friends,
All you have to do is to select all lines of code you want to comment or uncomment. To make this option visible go to View – Toolbars – and tick the Edit option. A new set of options will appear in the toolbar. Among them you will find the Comment/Uncomment buttons, as you can see in the image. On the Comments VBA page, there are macros that use the SendKeys method to open a comment for editing. For example, the following macro inserts a comment with no user name, and opens that comment so it is ready for editing. Below are the steps to change the color of the comment in Excel VBA: Open the Visual Basic Editor. Click the Tools option in the menu. Click on Options. In the Options dialog box, click on the ‘Editor Format’ tab. In the Code colors options, select Comment Text. Change the Foreground and/or the background color.
Providing proper short descriptions for each of your functions or statements etc. makes your VBA code – easy to read, easy to understand by anyone who refers your code.
Now the question is, how can you write description in English language in between your VBA code? VBA compiler will start giving compile error. It is very simple by commenting those lines which you do not want get executed.
How to comment a line in VBA code
In VBA to comment a particular line which you do not want to get compiled or executed, you can type your line followed by single quote ( ‘ ). The complete line which is starting with single quote is ignored and does not get executed. All the commented lines get formatted in green color as shown below image.
Commented line
It means to comment a block of code or lines you need to put single quote for each lines. It becomes difficult if you have got a function of hundreds of lines of code which you want to comment. then how to comment them all in simple way??
How to comment a block of codes or lines in VBA
In order to comment a block of lines at once, follow the below steps:
1. Select the Block which you want to comment
2. Click on comment Block option available as shown in below picture:
Commenting Block of codes in VBA
How to uncomment a block of codes or lines in VBA which are already commented
In order to un-comment a block of lines at once, follow the below steps:
1. Select the Block which you want to uncomment
2. Click on the un-comment Block option available as shown in below picture:
Where to find this comment Block Option in VBA window
Follow the below steps to enable or see this comment block option in VBA window:
1. To make this option visible follow : View –> Toolbars –> Click on Edit
Comment Block Option
Now import code to Excel Objects (First Make a backup for test)
In Feature: for new features search for XVBA - Live Server(Beta)
- Edit VBA from Excel And Access files in VSCode www.xvba.dev
- Create,install and share VBA Packages www.xvba.dev
- Create type definition files in 'vb' for auto-complete and share in www.xvba.dev
- Create Custom Ribbons Menus with Custom Images - See example
- Edit VBA from Access on VSCode
- Refectory Live Server for Excel and Access
- Update Autocomplete and Extension Size Reduce
- Add Hover functionality
- Add Go to Definition (Hold Ctr and Click on function/sub/param)
- Add Build and Production functionality (Files on folder xvba_unit_test will export to Excel/Access just on Production Mode )
System requirements:
- This extension was tested on Windows 10 and Office 2019
- This extension was not tested on Mac or Virtual Machines
- @localsmart/xvba-cli works on nodejs 12.18.4
Youtube
Youtube Chanel For Tutorials (Click Here)
- How to install - First Steps
- Namespace - Put File in Sub-folders
- Create Custom Ribbon Menu
- Use Production Mode or Build Mode
- How to Formatter Code With XVBA
- How to use Git With VBA
- Create Comment Block for VBA with XVBA
- Create Type Definition Files
- How to install node and use xvba-cli
- Use SQLite With VBA
- VBA Tutorials
In time, more Videos will came for Javascript/Typescript/React/Angular..
The list below is some off new features vba language will have with XVBA
- 1 Import excel VBA code to files (With error log)
- 2 *Namespace (Organize files in folders)
- 3 Live Server (With error log)
- 4 Run Macros from VSCode TreeView (With error log)
- 5 Auto Complete (Language Serve, in progress)
- 6 Syntax Highlighting
- 7 Snippets (starts with x-)
- 8 Auto Indentation Rules
- 9 Create Your own package and share in www.xvba.dev
- 10 Stop the Live server and load VBA files to Excel Manually
- 11 XVBA-CLI Command Line Interface for XVBA VSCode extension (@localsmart/xvba-cli)
- 12 Code Formatter - Got to settings search for formatter and set to local-smart.excel-live-server
- 13 Create Custom Ribbons Menus
- 14 Add Hover functionality
- 15 Add Go to Definition (Hold Ctr and Click on function/sub/param)
- 16 Add Build and Production functionality (Files on folder xvba_unit_test will export to Excel/Access just on Production Mode )
- Xvba Repository : www.xvba.dev
- Xvba-Cli : @localsmart/xvba-cli
Version Beta
- Add type definition files for auto-complete. See excel-types
- Add auto-complete for Local variables
- Add comment blocks for modules/class/sub/functions/props
- Stop live server on import vba files
- Xvba just import modules/class's and forms
Obs: The first comment block in the file is for modules/class namespace
- Fix import vba files
- For use excel Objects auto-complete install the package excel-types with @localsmart/xvba-cli See excel-types package on github
Contributing
Please contributions are welcomed and appreciated.
- See excel-types
All feedback are welcome.
- Mail : alberto.aeraph@gmail.com
- WhatsApp: +55 31 9 9229 5626
- Also please write a review, star me on GitHub, and follow me on github
- Github account: Aeraphe
Support XVBA
If you find it useful, please consider supporting it.
- Become a Sponsor � join the growing group of generous backers
Installation
(Save your work and create a copy, before setting up the server)
- First, set your excel security to run macros on open
- Second, click in the Bootstrap icon on XVBA (TreeView)
- This command will create a user config file (config.json)In this file you set the name of your excel file (xlsm,xlsb or xlam) andthe project root folder (Where your vba file will save)
Comment A Block In Vba In Excel Using
Obs: vba_folder path are relative to workspace and can't accept absolute path like : 'c:xxxx'
- Now Import VBA files, click in the import icon on XVBA (TreeView) (if excel file has vba code)
XVBA Live Server
- Click on Button to run XVBA Live Server (For edit files in VSCode and auto update Excel file)
- If you don't want to use Live Server just click on button 'Load VBA on Excel' to save your code changes on Excel when you want.
Use Git to track changes on your code
- Go to vscode terminal and type de command: git init (Press enter)
- See on: https://git-scm.com/
1 - Import excel VBA code to files (With error log)
- XVBA will import and create files for edit in VSCode.Obs: XVBA only import modules/class's/forms. Code inside sheets will not import Obs: modules name can not have accentuation
2- *Namespace
- Define the folder where your vba file (Class, Module,Form) will live
- For that, use the tag 'namespace' no vba files like:
'namespace=rootfolder/folder/subfolder
- You can use namespace snippet
3 - Live Server
- If you save VBA files changes in VSCode, it will automatically update your Excel file (like hot reload)
Obs: Import vba files button will stop Live Server
4 - Run Macros from VSCode TreeView (With error log)
- Right click on macros on 'LIST VBA MACROS' TreeView and select the option run
- The Macro will run on excel fileObs: Macros that receive params can not be run direct . Create a test file for that
A Log file 'excel_exec.log' wil create on workspace. Where you can see thesuccess or error on run Macro
To see Errors on VSCode, use On Error Resume Next on the first line of the VBA codeSet the error source name Err.Source ='func'
5 - Auto Complete
- Use the auto-complete code by a Language Server (not snippets)
6 - Syntax Highlighting
- This package provides syntax highlighting VBA.
7 - Snippets
- All xvba snippets starts with x-
Example (Block Comment): x-blc
Dim declarations
Sub/function
Module/Class/Form Files
- if/else
- for/while
- case
- etc...
8 - Auto Indentation Rules
VBScript by Darfka (Auto Indentation Rules)
Set *namespace for all your files to (sub-folder = your package name)
- Just commit your changes and push to git repository
git push
10 - Stop the Live Server and load VBA files to Excel Manually
11 - XVBA-CLI Command Line Interface for XVBA VSCode extension
- Add third packages to your project with command line interface
- Create Your own package and share xvba.dev
- Type on terminal and press enter for install the xvba-cli Last Version
SeeXVBA-CLI
12 - Code formatter
- Code formatter Got to settings search for formatter and set to local-smart.excel-live-serverFor format code short keys (alt+shift + f)
Problems with file encoding
If you are having problems with some especial characters you have tochange the default encode utf8 in vscode to windows1252 in settings.VBA files a save in windows1252 encoding
For that just pres (crtl + ,) and change the settings to:
- 'files.encoding': 'windows1252'
- 'files.autoGuessEncoding':true
This package is built with this plugins:
- VBScript by Darfka (Auto Indentation Rules)
- luggage66/vscode-vbscript (Syntaxe Highlighting)
Comment A Block In Vba In Excel Function
Versions Updates
- Move to CHANGELOG File
Bug Fix
- Move to CHANGELOG File