How to convert VBA to Google Apps Script?

前端 未结 5 1349
南笙
南笙 2021-01-17 23:06

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.

C

相关标签:
5条回答
  • 2021-01-17 23:40

    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

    0 讨论(0)
  • 2021-01-17 23:53

    This is currently impossible in google app script as there is neither worksheet selection change event nor selection change event in spreadsheet services. List of Google Spreadsheet events are Here.

    But we have time driven triggers in GAS, through this you will be able to run a function at some particular time. In your case lets say morning 12AM. You have to write a function which will run at 12AM to go through all the sheets and then format Cells(Target.Row, 1) and Cells(Target.Row, 2) on to the format which you like.

    Definitely you have to restructure your current spreadsheet... Welcome to Google App Scripting.

    0 讨论(0)
  • 2021-01-17 23:56

    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.

    0 讨论(0)
  • 2021-01-18 00:02

    If you want to convert from VBA tot GAS there is one site you really must look http://ramblings.mcpher.com/

    If that site doesn't help, I guess you're in big trouble!

    0 讨论(0)
  • 2021-01-18 00:02

    In 2020, Google released Macro Converter add-on, which automatically converts VBA to Apps Script.

    Note:

    • Only Enterprise users can acess to this add-on.
    • Some APIs cannot be converted automatically (e.g. operations on file system). You have to rewrite them by hand.
    0 讨论(0)
提交回复
热议问题