Convert VBA EXCEL code to Google App Script

63 views
Skip to first unread message

Innova Motor Concesionario

unread,
Dec 21, 2022, 3:37:11 AM12/21/22
to Google Apps Script Community
Hello everyone , I have an Excel document and I need help converting this VBA code into Google App Script language so I can use the document in google sheets. My company don´t have Excel and I have a problem, with this documment. 

Thank you very much in advance.

Here is the code:

' Code to have a checkbox, text box, and counter, so I can create copies of templates hidden and eliminate them if it´s necessary. 

Private Sub CheckBox1_Click()
Application.ScreenUpdating = False
general = ActiveSheet.Name
If CheckBox1.Value = True And TextBox1.Value = 1 Then Exit Sub
If SpinButton1.Enabled = False Then
SpinButton1.Enabled = True
TextBox1 = 1
Application.EnableEvents = False
With Sheets(Range("d5").Value)
.Visible = True
.Copy Before:=Sheets(Sheets.Count)
ActiveSheet.Name = Range("d5").Value & "_" & TextBox1.Value
.Visible = False
End With
Sheets(general).Activate
Else
confirm = MsgBox("Se va a eliminar la pestaña - " & Range("d5").Value & "_" & TextBox1.Value & "-. ¿Está seguro/a?", vbYesNo, "Confirme eliminación")
If confirm = vbYes Then
Application.DisplayAlerts = False
Sheets(Range("d5").Value & "_" & TextBox1.Value).Delete
Application.DisplayAlerts = True
SpinButton1.Enabled = False
TextBox1 = 0
Else: CheckBox1.Value = True
End If
Sheets(general).Activate
Application.EnableEvents = True
End If
Application.ScreenUpdating = True
End Sub

Private Sub SpinButton1_SpinUp()

Application.ScreenUpdating = False

general = ActiveSheet.Name
TextBox1 = TextBox1 + 1
CheckBox1.Enabled = False
If TextBox1 > 0 Then

Application.EnableEvents = False

With Sheets(Range("d5").Value)
.Visible = True
.Copy Before:=Sheets(Sheets.Count)
ActiveSheet.Name = Range("d5").Value & "_" & TextBox1.Value
.Visible = False
End With
Application.EnableEvents = True

Sheets(general).Activate
AppActivate Application.Caption
End If

Application.ScreenUpdating = True

End Sub

Private Sub SpinButton1_SpinDown()
general = ActiveSheet.Name

If TextBox1.Value > 1 Then
confirm = MsgBox("Se va a eliminar la pestaña - " & Range("d5").Value & "_" & TextBox1.Value & "-. ¿Está seguro/a?", vbYesNo, "Confirme eliminación")
    If confirm = vbYes Then
    Application.DisplayAlerts = False
    Application.EnableEvents = False
    Sheets(Range("d5").Value & "_" & TextBox1.Value).Delete
    Application.EnableEvents = True
    Application.DisplayAlerts = True
    TextBox1 = TextBox1 - 1
    If TextBox1 = 1 Then CheckBox1.Enabled = True
    Else
    Exit Sub
    End If
Else
If TextBox1 = 1 Then
CheckBox1.Value = False
GoTo fin:
End If
End If


fin:
Sheets(general).Activate
AppActivate Application.Caption
End Sub

' Code to have a button wich make the sum of all the Cell B3 of all the active tabs

Private Sub CommandButton1_Click()
For Each pesta In Worksheets
If pesta.Name <> Hoja1.Name And pesta.Name <> Hoja2.Name Then
horas = horas + Sheets(pesta.Name).Range("b3").Value
End If
Next pesta
Hoja2.Range("b3") = horas
End Sub

' Code to protect the book

Private Sub Workbook_Open()
Hoja1.Activate
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If ActiveSheet.Name <> [Hoja1].Name Then
If ThisWorkbook.ProtectStructure = True Then GoTo fin:
ThisWorkbook.Protect
Else
ThisWorkbook.Unprotect
End If
fin:
End Sub
Reply all
Reply to author
Forward
0 new messages