My company is switching from Microsoft Office to Google Docs, I have this (several) code I want to use in Google Spreadsheets but I have no idea on how to do that.
Consider this sample of code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("E:J")) Is Nothing Then
Cells(Target.Row, 1) = MonthName(Month(Date))
Cells(Target.Row, 2) = Format(Now, "mm/dd/yyyy")
End If
End Sub
Your best chance for success is to use the VBA Sub as a kind of specification; if you can clearly explain what functionality is implemented by a VBA Sub, you have the basis for a specification for a new function implemented in your google spreadsheet. You can convert VBA to Google script automatically by using GSpread.NET .
You have built up an expertise and body of work in VBA, but your company is now seriously considering moving to Google Apps and ditching Microsoft Office products. Is it the end of the world? Actually, in the end it’s not so hard. You can find the application and test data in the VBA to Google Apps Script Roadmapper project download.
You’ll also find some adapted material from the book here. VBA is to Office as Google Apps Script is to Google Apps. Those tasks to automate repetitive sequences, or extend the functionality of Office can usually be done in Google Apps Script.
These APIs tend to perform critical operations for a macro, like connecting to a database or accessing a local resource, and Apps Script is generally not a good solution. On your computer, open Google Drive. On the right side panel, click the Macro Converter add-on .
Use GSpread.NET. to work with Google Spreadsheets by using Microsoft Excel API. You needn't rewrite all code, just replace CreateObject(Excel.Application) to CreateObject(GSpreadCOM.Application).
examples
In 2020, Google released Macro Converter add-on, which automatically converts VBA to Apps Script.
Note:
The function is structured like this:
Private Sub Worksheet_Change(ByVal Target As Range)
Statements here
End Sub
That would probably convert to something like:
function Worksheet_Change(ByVal) {
Statements Here;
};
Instead of End Sub
the function in JavaScript ends with a curly brace }
.
Instead of End If
, the If, then statement also ends with a curly brace }
.
if (condition) {code here;}
That's the syntax for a JavaScript If statement. There is no Then
key word in JavaScript.
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