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.
Much obliged.
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: