Last active
December 8, 2022 22:16
-
-
Save HiroNakamura/60dfe07b5306c9e8a98482de84556c19 to your computer and use it in GitHub Desktop.
VBA en ejemplos no. 6.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Prueba() | |
'Visto en: https://es.stackoverflow.com/questions/183891/error-de-subindice-fuera-de-intervalo-en-excel-macros-vda | |
Dim ss As Workbook | |
Dim archivo As Workbook | |
Dim nombreArchivo As Variant | |
Set ss = ActiveWorkbook | |
nombreArchivo = Application.GetOpenFilename(FileFilter:="Excel Files,*.xl*;*.xm*") | |
If nombreArchivo = False Then | |
Exit Sub | |
Else | |
With Application | |
.ScreenUpdating = False | |
.EnableEvents = False | |
End With | |
End If | |
Set archivo = Workbooks.Open(nombreArchivo) | |
Dim AA As String | |
AA = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row | |
archivo.Sheets("Hoja1").Range("A1:A" & AA).Copy: ss.Sheets("Hoja1").Range("A1").PasteSpecial xlPasteValues | |
Application.GoTo ss.Sheets("Hoja1").Range("A1") | |
archivo.Close | |
End Sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Visto en: https://es.stackoverflow.com/questions/194752/extraer-texto-de-sap-y-copiar-en-excel-sap-script | |
Sub creadorGD() | |
Dim application | |
Dim connection | |
Set objsheet = ActiveWorkbook.ActiveSheet | |
H = Range("B7") | |
sucursal = Range("C7") | |
'determina cecos y centros | |
If sucursal = "ARICA" Then | |
ceco = "11010180" | |
centro = "1010" | |
End If | |
If sucursal = "IQUIQUE" Then | |
ceco = "11010280" | |
centro = "1011" | |
End If | |
If sucursal = "CALAMA" Then | |
ceco = "11010480" | |
centro = "1013" | |
End If | |
If sucursal = "ANTOFAGASTA" Then | |
ceco = "11010380" | |
centro = "1012" | |
End If | |
If sucursal = "COPIAPO" Then | |
ceco = "11020180" | |
centro = "1020" | |
End If | |
If sucursal = "LASERENA" Then | |
ceco = "11020280" | |
centro = "1021" | |
End If | |
If sucursal = "PLACILLA" Then | |
ceco = "11020380" | |
centro = "1022" | |
End If | |
If sucursal = "LASCONDES" Then | |
ceco = "11080284" | |
centro = "1071" | |
End If | |
If sucursal = "CANTAGALLO" Then | |
ceco = "11080184" | |
centro = "1070" | |
End If | |
If sucursal = "LADEHESA" Then | |
ceco = "11080484" | |
centro = "1073" | |
End If | |
If sucursal = "MACKENNA" Then | |
ceco = "11070680" | |
centro = "1087" | |
End If | |
If sucursal = "SANBERNARDO" Then | |
ceco = "11070780" | |
centro = "1088" | |
End If | |
If sucursal = "SANTIAGO" Then | |
ceco = "11070186" | |
centro = "1081" | |
End If | |
If sucursal = "QUILICURA" Then | |
ceco = 11070280 | |
centro = 1082 | |
End If | |
If sucursal = "RANCAGUA" Then | |
ceco = "11030180" | |
centro = "1030" | |
End If | |
If sucursal = "CURICO" Then | |
ceco = "11030280" | |
centro = "1031" | |
End If | |
If sucursal = "TALCA" Then | |
ceco = "11030380" | |
centro = "1032" | |
End If | |
If sucursal = "CHILLAN" Then | |
ceco = "11040380" | |
centro = "1040" | |
End If | |
If sucursal = "CONCEPCIÓN" Then | |
ceco = "11040180" | |
centro = "1041" | |
End If | |
If sucursal = "LOSANGELES" Then | |
ceco = "11050180" | |
centro = "1050" | |
End If | |
If sucursal = "TEMUCO" Then | |
ceco = "11050280" | |
centro = "1051" | |
End If | |
If sucursal = "VALDIVIA" Then | |
ceco = "11050380" | |
centro = "1052" | |
End If | |
If sucursal = "OSORNO" Then | |
ceco = "11060180" | |
centro = "1060" | |
End If | |
If sucursal = "LLANQUIHUE" Then | |
ceco = "11060280" | |
centro = "1061" | |
End If | |
If sucursal = "COYHAIQUE" Then | |
ceco = "11060580" | |
centro = "1064" | |
End If | |
If sucursal = "PUNTAARENAS" Then | |
ceco = "11060680" | |
centro = "1065" | |
End If | |
If sucursal = "PREVENTA" Then | |
ceco = "11002624" | |
centro = "1003" | |
End If | |
receptor = Range("D7") | |
fecha = Format(Date, "dd.mm.yyyy") | |
If Not IsObject(application) Then | |
Set SapGuiAuto = GetObject("SAPGUI") | |
Set application = SapGuiAuto.GetScriptingEngine | |
End If | |
If Not IsObject(connection) Then | |
Set connection = application.Children(0) | |
End If | |
If Not IsObject(session) Then | |
Set session = connection.Children(0) | |
End If | |
If IsObject(WScript) Then | |
WScript.ConnectObject session, "on" | |
WScript.ConnectObject application, "on" | |
End If | |
'priemra parte | |
'session.findById("wnd[0]").maximize | |
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nZ_GD_MAQUINA" | |
session.findById("wnd[0]").sendVKey 0 | |
session.findById("wnd[0]/usr/ctxtKNA1-KUNNR").Text = centro | |
session.findById("wnd[0]/usr/ctxtW_FECHA").Text = fecha | |
session.findById("wnd[0]/usr/ctxtTVSTZ-WERKS").Text = "1003" | |
session.findById("wnd[0]/usr/ctxtZAREAVTA-BUKRS").Text = "1000" | |
session.findById("wnd[0]/usr/txtW_TEXTO").Text = receptor | |
session.findById("wnd[0]/usr/txtW_TEXTO").SetFocus | |
'session.findById("wnd[0]/usr/txtW_TEXTO").caretPosition = 18 | |
session.findById("wnd[0]").sendVKey 0 | |
session.findById("wnd[0]/usr/txtW_TEXTO").Text = receptor | |
session.findById("wnd[0]/usr/txtW_TEXTO").SetFocus | |
'session.findById("wnd[0]/usr/txtW_TEXTO").caretPosition = 18 | |
session.findById("wnd[0]").sendVKey 0 | |
session.findById("wnd[0]/usr/btnBTN_MATCH").press | |
session.findById("wnd[1]/usr/lbl[21,5]").SetFocus | |
'session.findById("wnd[1]/usr/lbl[21,5]").caretPosition = 64 | |
session.findById("wnd[1]").sendVKey 2 | |
session.findById("wnd[0]/usr/tblZSD_GENERA_ZSGCDETALLE/txtT_DETALLE-ARKTX[0,0]").Text = H | |
session.findById("wnd[0]/usr/tblZSD_GENERA_ZSGCDETALLE/txtT_DETALLE-KWMENG[1,0]").Text = "1" | |
session.findById("wnd[0]/usr/tblZSD_GENERA_ZSGCDETALLE/txtT_DETALLE-NETWR[2,0]").Text = "700000" | |
session.findById("wnd[0]/usr/tblZSD_GENERA_ZSGCDETALLE/txtT_DETALLE-NETWR[2,0]").SetFocus | |
session.findById("wnd[0]/usr/tblZSD_GENERA_ZSGCDETALLE/txtT_DETALLE-NETWR[2,0]").caretPosition = 7 | |
session.findById("wnd[0]").sendVKey 0 | |
session.findById("wnd[0]/usr/btnGENERAR").press | |
'favor copiar numero | |
MsgBox "favor guarde numero de guia, muy importante" | |
' session.findById("wnd[1]/usr/cntlCC1/shellcont/shell").setSelectionIndexes 20, 28 | |
' Selection.Copy | |
'session.findById("wnd[1]/tbar[0]/btn[0]").press | |
'Status = session.findById("wnd[0]/sbar").Text | |
'objsheet.Cells(10, 2) = Status | |
'session.findById("wnd[0]/tbar[0]/btn[15]").press | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment