0
Good,
I have this VBA code and needed to build a Javascript for Google Docs that do the same thing. It is possible to convert VBA to Javascript?
Thank you.
Private Sub CommandButton1_Click()
Dim F1 As Worksheet
Dim intervalo As Range
Dim LastRow As Long
'Declara a Planilha pelo nome
Set F1 = ThisWorkbook.Worksheets("Folha1")
'Última Linha
LastRow = F1.Cells(F1.Rows.Count, "A").End(xlUp).Row
Set intervalo = F1.Range("A2:A" & LastRow)
'Caso não encontre TextBox2
If TextBox2 = "" Then
MsgBox "Insira o nº da ficha a consultar."
'Se os campos de TextBox estiverem preenchidos
ElseIf TextBox2 > "" And TextBox1 > "" Then
'Realiza a procura
With intervalo
Set cellFound = .Find(TextBox1, LookIn:=xlValues)
If Not cellFound Is Nothing Then
FirstAddress = cellFound.Address
Do
'Realiza Ação após encontrar, faz offset de uma coluna para direita e segue o hyperlink. Então após encontrar na Coluna A, segue o hyperlink da coluna B.
cellFound.Offset(0, 1).Hyperlinks(1).Follow
Set cellFound = .FindNext(cellFound)
Loop While Not cellFound Is Nothing And cellFound.Address <> FirstAddress
End If
End With
End If
TextBox2.SetFocus
End Sub
Private Sub TextBox1_Change()
Dim intervalo As Range
Dim texto As String
Dim codigo As Integer
Dim pesquisa
Dim mensagem
Dim F1 As Worksheet
Set F1 = ThisWorkbook.Worksheets("Folha1")
LastRow = F1.Cells(F1.Rows.Count, "A").End(xlUp).Row
On Error Resume Next
codigo = TextBox1.Text
Set intervalo = F1.Range("A2:B" & LastRow)
pesquisa = Application.WorksheetFunction.VLookup(codigo, intervalo, 2, False)
TextBox2.Text = pesquisa
End Sub
'Private Sub UserForm_Terminate()
'ActiveWorkbook.Close Savechanges:=False
'End Sub
Good Philip, first of all thank you. I copied the code to my drive and when I click the search on the sidebar appears a message "the page may be temporarily unavailable or have been removed". Did I do something wrong? Thank you
– R.Galamba
Is the link from the document I shared working? I let it out so anyone could access the code and the example works. To copy the code it would be good to create a copy of the document and code and run the showSidebar method inside the script app to get the necessary permissions.
– FilipeTD
I did a test now. If you make a copy of the document the code in app script will be copied as well. After copying enter the Script Editor by the path: Tools > Script Editor and run the showSidebar method. A screen will appear saying that the page is not safe. This is because it was a method made by a user and was not published in the google codes. You can continue and accept the permissions to work. Any questions just contact me.
– FilipeTD
Good Philip, thank you for your help and I want to ask if it is possible when we search for the code when it appears the link can be clicked on the link and open the page?
– R.Galamba
Your pop-up must be blocked for browser security reasons. Allow the pop-up for that site and perform the test that should work.
– FilipeTD
The alerts I showed are only to show that the values are being picked up. You can comment on these codes that the site will open the same way.
– FilipeTD