Automation error? What is this?

perezpa

New Member
Joined
Jun 17, 2011
Messages
17
I've never seen this error when running a macro. Then again, I've never used a VB script either. Help?

The bolded/underlined line is where I get the error.

Rich (BB code):
Option Explicit

Sub Incentivos_PressTo()

Dim Año As Integer
Dim Periodo As Integer
Dim Periodo2 As String
Dim filePath As String
Dim fileName As String
Dim Usuario As String
Dim Contraseña As String
Dim Centro As Variant

Usuario = Range("D2").Value
Contraseña = Range("D3").Value
Periodo = Range("D5").Value
Año = Range("D6").Value
Centro = Range("D7").Value
If Periodo < 10 Then
    Periodo2 = "0" & CStr(Periodo)
    Else: Periodo2 = CStr(Periodo)
End If
filePath = "C:\Users\peperez\Desktop\Archivos\Incentivos Press-To\"
fileName = Año & Periodo2 & ".xlsm"

'Correr vbs de SAP ======================================================================================================
Dim MyApp As Variant
Dim SapGuiAuto As Variant
Dim MyConnection As Variant
Dim Session As Variant

Set SapGuiAuto = GetObject("SAPGUI")
Set MyApp = SapGuiAuto.GetScriptingEngine
Set MyConnection = MyApp.Children(0)
Set Session = MyConnection.Children(0)

With Session
    .findById("wnd[0]").maximize
    .findById("wnd[0]/usr/txtRSYST-BNAME").Text = Usuario
    .findById("wnd[0]/usr/pwdRSYST-BCODE").Text = Contraseña
    .findById("wnd[0]/usr/pwdRSYST-BCODE").SetFocus
    .findById("wnd[0]/usr/pwdRSYST-BCODE").caretPosition = 9
    .findById("wnd[0]").sendVKey 0
    .findById("wnd[0]/tbar[0]/okcd").Text = "ke80"
    .findById("wnd[0]").sendVKey 0
    .findById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[0,21]").Text = "grco"
    .findById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[0,21]").caretPosition = 4
    .findById("wnd[1]").sendVKey 0
    .findById("wnd[0]").resizeWorkingPane 176, 35, False
    .findById("wnd[0]/shellcont").dockerPixelSize = 482
    .findById("wnd[0]/shellcont/shell").selectedNode = "000000001027"
    .findById("wnd[0]/shellcont/shell").doubleClickNode "000000001027"
    .findById("wnd[0]/usr/ctxtPAR_08").Text = Periodo
    .findById("wnd[0]/usr/ctxtPAR_09").Text = Periodo
    .findById("wnd[0]/usr/ctxtPAR_11").Text = Año
    .findById("wnd[0]/usr/ctxtPAR_10").Text = "0"
    .findById("wnd[0]/usr/ctxtPAR_02").Text = Centro
    .findById("wnd[0]/usr/ctxtPAR_01").Text = "co-grer"
    .findById("wnd[0]/usr/ctxtPAR_01").SetFocus
    .findById("wnd[0]/usr/ctxtPAR_01").caretPosition = 7
    .findById("wnd[0]").sendVKey 8
    .findById("wnd[0]/mbar/menu[0]/menu[11]").Select
    .findById("wnd[1]/usr/btnD2000_PUSH_01").press
    .findById("wnd[1]/tbar[0]/btn[6]").press
    .findById("wnd[1]/usr/sub:SAPLKEC1:0100/chkCEC01-CHOICE[0,0]").Selected = True
    .findById("wnd[1]/tbar[0]/btn[0]").press
    .findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[0,0]").Select
    .findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[0,0]").SetFocus
    .findById("wnd[1]/tbar[0]/btn[0]").press
    .findById("wnd[1]/tbar[0]/btn[0]").press
End With
'==========================================================================================================================

    ActiveSheet.Columns("B:E").Cut Destination:=Columns("C:F")
    ActiveSheet.Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
        FieldInfo:=Array(Array(0, 1), Array(21, 1)), TrailingMinusNumbers:=True
    
    ChDir "C:\Users\peperez\Desktop\Archivos\Incentivos Press-To"
    ActiveWorkbook.SaveAs fileName:=filePath & fileName _
        , FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
        
End Sub

Much obliged.
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi perezpa,

Maybe adding the path of the object helps, something like:



Code:
Set SapGuiAuto = GetObject("C:\YOUR_PATH\SAPGUI")

Hope this helps.

Regards.
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,794
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top