特定VBA功能(例如SendKeys

时间:2019-05-22 15:48:46

标签: excel vba google-apps-script

我的工作场所正在从Office 365更改为GSuite。

如何将VBA中创建的宏成功移动到Apps脚本。

几乎所有的宏都包含函数SendkeysAppactivate,我似乎找不到与之等效的Apps Script。

这些宏也使用了大量的IE自动化程序。

以下是我在VBA中的一些代码示例,我希望在Apps脚本中重新制作。

Sub RetrieveCounts()
    Dim strBaseURL As String 'This is where Internet Explorer will go when it is launched
    Dim rngA As Range 'This will store the range
    Dim IE As InternetExplorerMedium 'This will be what actually controls internet explorer when it is launched
    Dim sht As String 'This will store the sheet that is open
    Dim user As String 'This will store the username
    Dim pass As String 'This will store the password
    Dim failure As Boolean 'This asks whether or not the receiver failed as a true and false value
    Dim serialNumber As String 'This stores the serial number
    Dim choppedString As String 'This stores the whole string as it is being chopped up for the RA reasons
    Dim colon As Long 'This finds the colons in the string
    Dim comma As Integer 'This finds the commas in the string
    Dim jobType As String 'This gets the job type
    Dim returnReason As String 'This stores the return reason
    Dim techLog As String 'This stores the tehcs login ID
    Dim techName As String 'This stores the techs name
    Dim userName As String 'This stores the users name
    Dim userOrg As String

    Set clip = New MSForms.DataObject
    userOrg = Sheets(4).Range("B6").Value

    Set IE = New InternetExplorerMedium 'Open up Internet explorer

    strBaseURL = "http://mnet.dish.com/Reports_interactive/DNS_ON_HAND_QTY.asp" 'Set's what IE will go to once it is launched
    With IE 'If something does not have an object that it is being run on, run on IE
    .Visible = True 'makes IE visible so that you can see what is going on, setting to false will cause the window to not show up and not run properly
    .Navigate strBaseURL 'Go to the webpage defined earlier
    Application.Wait Now + #12:00:02 AM#
    Do Until .Busy = False: DoEvents: Loop 'Repeat this line until the page is %100 loaded

    For Each ietag In .Document.forms("theForm").ORG.getElementsbyTagName("Option") 'Find the org number in the webpage
        If Left(ietag.outertext, 3) = userOrg Then
            choppedString = (InStr(ietag.outerhtml, "=") + 1)
            choppedString = (Right(ietag.outerhtml, Len(ietag.outerhtml) - choppedString))
            choppedString = Left(choppedString, 3)
            .Document.forms("theForm").ORG.Value = choppedString
            Exit For
        End If
    Next ietag

    '.Document.forms("theForm").ORG.Value = "228"
    .Document.getElementById("MainForm").FirstChild.Click
    Application.Wait Now + #12:00:02 AM#
    Do Until .Busy = False: DoEvents: Loop 'Repeat this line until the page is %100 loaded
    '.Document.getElementById("CopyBtn").Click

    clip.SetText IE.Document.getElementById("copyspan").outerhtml
    clip.PutInClipboard

    Sheets("Counts").Activate
    Sheets("Counts").Cells.Select
    Selection.Delete

    Sheets("Counts").Paste Destination:=Worksheets("Counts").Range("A1:A1")

    Sheets("UER").Activate
    Sheets("UER").Range("A1").Select

    End With

    IE.Quit
quickStop:
End Sub
Sub Issue_SHS() 'Used to automatically issue the SHS Items
    Dim partNumber As String
    Dim vanNumber As String
    Dim quantity As Integer
    Dim workOrder As String
    Dim cellValue As String
    Dim serial As String
    Dim openingParen As Integer
    Dim closingParen As Integer
    Dim startingCell As String
    Dim startingRow As String
    Dim rngG As Range
'    On Error GoTo Errorcatch

    If CapsLocks = True Then
        MsgBox "Gayle, turn off your Caps Lock..."
    Else
    shsissue = 0 'Sets this to 0 in the case the you have to hit issue more than one time for whatever reason
    'startingCell = "G" & InputBox("Where would you like to start?") & ":G65536" 'Gets where you would like to start the process
    startingCell = IssueRange(True)
    Set rngG = Worksheets("UER").Range(startingCell) 'This get the range that the macro will run at
    For Each cell In rngG 'Starts the loop
        cellValue = cell 'Get the string inside of the cell
        openingParen = InStr(cellValue, "[") 'Gets the opening square bracket
        closingParen = InStr(cellValue, "]") 'Gets the closing square bracket
        If openingParen > 0 Then 'Makes sure that the first bracket returned something, otherwise it skips
            If cell.Offset(0, -1).Value = "Smart Home Services" Then 'Makes sure that the item in question is an SHS item
                If cell.EntireRow.Hidden = False Then 'Makes sure that the row is not hidden
                    partNumber = Mid(cellValue, openingParen + 1, closingParen - openingParen - 1) 'Get the part number between the brackets
                    vanNumber = cell.Offset(0, 11).Value 'Finds the van number
                    quantity = cell.Offset(0, 2).Value 'Finds the quantity to issue
                    workOrder = cell.Offset(0, 6).Value 'Finds the WO to issue the item to
                    AppActivate ("Oracle Applications - PERP") 'Brings the Oracle page up
                    SendKeys partNumber & "{TAB}" & vanNumber & "{TAB}" & "{TAB}" & quantity & "{TAB}" & "{TAB}" & "I" & "{TAB}" & workOrder, True 'Mimics the keystrokes to issue the item
                    If Not cell.Offset(0, 1) = "" Then 'Checks if there is a serial number for the SHS Item
                        serial = UCase(cell.Offset(0, 1).Value)
                        SendKeys "%r" 'Opens the Serial Number Menu
                        SendKeys serial & "{DOWN}" 'Mimics the keystrokes for the serial number and hits the down arrow
                        SendKeys "{ENTER}" 'Hits the enter key
                    End If
                    SendKeys "{TAB}" 'Sends the cursor to the next line
                End If
            End If
        End If
    Next cell
    End If

Done: 'This is used for debugging to find where an error occurs
'Errorcatch:
'    MsgBox Err.Description
End Sub

0 个答案:

没有答案