如何将 VBA 脚本自动转换为 Google Apps 脚本? [英] How to convert VBA script to Google Apps Script automatically?

查看:42
本文介绍了如何将 VBA 脚本自动转换为 Google Apps 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VBA 是编写 excel 宏的语言.Google 表格仅支持将 Google 应用脚本作为宏语言.是否有直接或自动的方法将 VBA 脚本转换为 Google Apps 脚本脚本而无需重写代码?

这是我正在尝试转换的示例 VBA 脚本:

Private Sub Worksheet_Change(ByVal Target As Range)Dim rngStart As Range, rngCrit As Range设置 rngStart = Range("A3")设置 rngCrit = Range("B1")出错时转到退出点Application.EnableEvents = False如果不相交(目标,rngCrit)什么都没有范围(rngStart, Cells(Rows.Count, rngStart.Column).End(xlUp)).ClearContents如果 Val(rngCrit) >0 那么使用 rngStart.Resize(Val(rngCrit)).Value = "=ROW()-";&rngStart.Row - 1.Value = .Value结束于万一万一出口点:设置 rngStart = 无设置 rngCrit = 无Application.EnableEvents = True结束子

我的尝试:

我尝试用一​​些等效的 Google 脚本替换一些命令.我的问题是我想得太线性了.我正在尝试以与 VBA 完全相同的方式进行编码,并且只是尝试将关键字从 VBA 切换到 Google Script 中的关键字.我希望有一种直接的方法.

解决方案

您可以使用 GSpread.NET 自动将 VBA 转换为 Google 脚本.它库允许使用 Microsoft Excel API 读取和写入 Google 电子表格.示例:http://scand.com/products/gspread/tutorial.html>

VBA is the language, in which excel macros were written. Google sheets only supports Google apps script as a macro language. Is there a direct or automatic way to convert a VBA script to a Google Apps Script script without rewriting the code?

Here is a sample VBA script, that I am trying to convert:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rngStart As Range, rngCrit As Range
    Set rngStart = Range("A3")
    Set rngCrit = Range("B1")
    On Error GoTo ExitPoint
    Application.EnableEvents = False
    If Not Intersect(Target, rngCrit) Is Nothing Then
        Range(rngStart, Cells(Rows.Count, rngStart.Column).End(xlUp)).ClearContents
        If Val(rngCrit) > 0 Then
            With rngStart.Resize(Val(rngCrit))
                .Value = "=ROW()-" & rngStart.Row - 1
                .Value = .Value
            End With
        End If
    End If
ExitPoint:
    Set rngStart = Nothing
    Set rngCrit = Nothing
    Application.EnableEvents = True
End Sub

What I've tried:

I've tried to substitute some of the commands with some of the equivalent Google Scripts. My issue is I am thinking too linear. I am trying to code the same exact way as VBA and just trying to switch keywords from VBA to ones in Google Script. I was hoping there was a direct method.

解决方案

You can convert VBA to Google script automatically by using GSpread.NET. It library allows read and write Google Spreadsheets by using Microsoft Excel API. examples: http://scand.com/products/gspread/tutorial.html

这篇关于如何将 VBA 脚本自动转换为 Google Apps 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆