execWB works from Excel VB script but same code throws RPC exception in Powershell Script

0

Errors from Powershell version.....

Exception calling "Quit" with "0" argument(s): "The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)" At C:\Users\robp\Desktop\nbrs.ps1:19 char:13 + $ie.quit <<<< () + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ComMethodCOMException

Exception calling "ExecWB" with "2" argument(s): "The remote procedure call failed. (Exception from HRESULT: 0x800706BE)" At C:\Users\robp\Desktop\nbrs.ps1:12 char:19 + $ie.ExecWB <<<< (6,2) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ComMethodTargetInvocation

Powershell version......

$reader = [System.IO.File]::OpenText("c:\users\robp\desktop\conveyance.txt")
try {
    $ie = New-Object -comobject InternetExplorer.Application 
    $ie.visible = $true 
    # $ie.silent = $true 
    for(;;) {
        $line = $reader.ReadLine()
        if ($line -eq $null) { break }
        $url = "http://xxx.xxx.xxx.xxx/specdata/specdata.asp?requiredmcpartno=" + $line
        $ie.Navigate( $url )
        while( $ie.busy){Start-Sleep 4} 
        $ie.ExecWB(6,2)
    }
    while( $ie.busy){Start-Sleep 4} 
    $ie.quit()
}
finally {
    while( $ie.busy){Start-Sleep 4} 
    $ie.quit()
    $reader.Close()
}

VBA behind button in excel....

Private Sub CommandButton1_Click()
    Dim urlData As String
    Dim part As String
    Dim myFile As String

    myFile = "N:\conv\conveyance.txt"


    Const OLECMDID_PRINT = 6
    Const OLECMDEXECOPT_DONTPROMPTUSER = 2
    Const PRINT_WAITFORCOMPLETION = 2

    Set Browser = CreateObject("InternetExplorer.Application")

    Open myFile For Input As #1
    Do Until EOF(1)
    Line Input #1, part
        urlData = "http://xxx.xxx.xxx.xxx/specdata/specdata.asp?requiredmcpartno=" + part
        Browser.navigate (urlData)
        Browser.Visible = True

        Do While Browser.ReadyState <> 4
            Application.Wait (1000)
        Loop

        Browser.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
    Loop
    Close #1
End Sub
vba
excel
powershell
asked on Stack Overflow Aug 9, 2014 by Henry Todd • edited Oct 17, 2018 by user692942

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0