Export SAP to excel completely via VBA

ε祈祈猫儿з 提交于 2019-12-02 11:42:21

Sorry, I used only a small amount of data for my tests. Therefore, an extension must now be incorporated into the proposed construction.

for example:

ExportInvest: (in myTest.xlsm)

. . .
'Dim FileName As String
. . .
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "S:\FL_DMA\SAP Scripts\test\backup"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = FileName
session.findById("wnd[1]/tbar[0]/btn[0]").press

Set wshell = CreateObject("Wscript.Shell")
'-----------------------------------------new
wshell.Run "c:\tmp\myTest.vbs" & " " & "myTest.xlsm" & " " & FileName
'-----------------------------------------new
End Sub

myTest.vbs:

set xclapp = getObject(,"Excel.Application")

'-----------------------------------------new
on error resume next
do 
 err.clear
 Set xclwbk = xclApp.Workbooks.Item(wscript.arguments(1))
 If Err.Number = 0 Then exit do
 wscript.sleep 2000
loop
on error goto 0
'-----------------------------------------new

xclapp.Run wscript.arguments(0) & "!ExportInvest_1"

ExportInvest_1: (in myTest.xlsm)

Public FileName as String

Sub ExportInvets_1()
 'Dim Today as String
 'Today = Format$(DateTime.Now, "yyyymmdd__hh-MM-ss")

 MsgBox "file open", vbOKOnly, ""
 Workbooks(FileName).Activate
 Worksheets(1).Range("A2:K100").Select
 Selection.Copy ThisWorkbook.Worksheets("Input").Range("A2:K100")
End Sub

Regards, ScriptMan

I would solve it as follows:

ExportInvest: (in myTest.xlsm)

. . .
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "S:\FL_DMA\SAP Scripts\test\backup"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = FileName
session.findById("wnd[1]/tbar[0]/btn[0]").press

'new commands
Set wshell = CreateObject("Wscript.Shell")
wshell.Run "c:\tmp\myTest.vbs" & " " & "myTest.xlsm"
End Sub

myTest.vbs:

set xclapp = getObject(,"Excel.Application")
xclapp.Run wscript.arguments(0) & "!ExportInvest_1"

ExportInvest_1: (in myTest.xlsm)

Sub ExportInvets_1()
    Dim Today as String
    Today = Format$(DateTime.Now, "yyyymmdd__hh-MM-ss")

    MsgBox "file open", vbOKOnly, ""
    Workbooks("Invest_" & Today).Activate
    Worksheets(1).Range("A2:K100").Select
    Selection.Copy ThisWorkbook.Worksheets("Input").Range("A2:K100")
End Sub

Regards, ScriptMan

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!