How to print from SAP by using VBA?

vitor

New Member
Joined
Sep 26, 2017
Messages
5
Hi could someone help with a VBA which automatically runs a VBS sap script from excel?
i'd like to print the reservations already made.In this case, i have to mark each file that i want to print, manually.So, how do i tell the program that i want to print only the 5 or 10 last reservations made.
Thanks!


<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;">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

End If
session
.findById("wnd[0]").maximize

session
.findById("wnd[0]/tbar[0]/okcd").text = "/nzmb25"

session
.findById("wnd[0]").sendVKey 0

session
.findById("wnd[0]/usr/ctxtWERKS-LOW").text =

session
.findById("wnd[0]/usr/ctxtBDTER-LOW").text =

session
.findById("wnd[0]/usr/txtUSNAM-LOW").text =

session
.findById("wnd[0]/usr/txtUSNAM-LOW").setFocus

session
.findById("wnd[0]/usr/txtUSNAM-LOW").caretPosition = 5

session
.findById("wnd[0]/tbar[1]/btn[8]").press

session
.findById("wnd[0]/usr/chk[1,38]").selected = true

session
.findById("wnd[0]/usr/chk[1,38]").setFocus

session
.findById("wnd[0]/tbar[1]/btn[20]").press

session
.findById("wnd[0]/tbar[1]/btn[19]").press

session
.findById("wnd[1]/usr/chkITCPP-TDDELETE").selected = true

session
.findById("wnd[1]/usr/chkITCPP-TDIMMED").selected = true

session
.findById("wnd[1]/usr/chkITCPP-TDIMMED").
setFocus

session
.findById("wnd[0]/usr/chk[1,37]").selected = true

session
.findById("wnd[0]/usr/chk[1,37]").setFocus

session
.findById("wnd[0]/tbar[1]/btn[19]").press

session
.findById("wnd[1]/usr/chkITCPP-TDIMMED").selected = true

session
.findById("wnd[1]/usr/chkITCPP-TDDELETE").selected = true

session
.findById("wnd[1]/usr/chkITCPP-TDDELETE").
setFocus




session
.findById("wnd[0]/usr/chk[1,36]").selected = true

session
.findById("wnd[0]/usr/chk[1,36]").setFocus

session
.findById("wnd[0]/tbar[1]/btn[19]").press

session
.findById("wnd[1]/usr/chkITCPP-TDIMMED").selected = true

session
.findById("wnd[1]/usr/chkITCPP-TDDELETE").selected = true

session
.findById("wnd[1]/usr/chkITCPP-TDDELETE").setFocus
</code>
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi and welcome to the MrExcel Message Board,

I am not sure if I will be of much help. I no longer have access to SAP and did not use mb25 even when I did - and you have a custom version of it!

However, somehow, you need to find the last row of your data. Is there a button to move to the end of the report? If you can identify the last row number then you can get the script to loop round the last x rows to select them.

To do that you will need to modify one of the checkbox setting lines. For example, this will check rows 10 to 15:
Code:
    For i = 10 To 15
        session.findById("wnd[0]/usr/chk[1," & i & "]").Selected = True
    Next
Note: I do not know whether you need to do anything other then set the checkbox inside the loop.

I hope this helps.


Regards,
 
Upvote 0
Yes! It worked! thank you very much!

That's how i wrote my code:


For i = 13 To 14 'contagem de célula das reservas


session.findById("wnd[0]/usr/chk[1," & i & "]").Selected = True 'alteração para as celulas de acordo com o loop
session.findById("wnd[0]/usr/chk[1," & i & "]").SetFocus
session.findById("wnd[0]/tbar[1]/btn[20]").press
session.findById("wnd[1]/tbar[0]/btn[6]").press
session.findById("wnd[2]/usr/chkITCPP-TDDELETE").Selected = True
session.findById("wnd[2]/usr/chkITCPP-TDIMMED").Selected = True
session.findById("wnd[2]/usr/chkITCPP-TDIMMED").SetFocus
session.findById("wnd[2]/usr/chkITCPP-TDDELETE").SetFocus
session.findById("wnd[2]/tbar[0]/btn[86]").press
session.findById("wnd[0]/usr/chk[1," & i & "]").Selected = False

next i

In case that i need to creat a reservation. and i need to find the last used row in a column

Should i do like this?

[TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64"]Cells(Rows.Count,"A").End(xlUp).Offset(1,0).Row[/TD]
[/TR]
</tbody>[/TABLE]
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "/nmb21"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRM07M-BWART").text = "261"
session.findById("wnd[0]/usr/ctxtRM07M-WERKS").text = "1104"
session.findById("wnd[0]/usr/ctxtRM07M-WERKS").setFocus
session.findById("wnd[0]/usr/ctxtRM07M-WERKS").caretPosition = 4
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/txtRKPF-WEMPF").text = "DIMAL"
session.findById("wnd[0]/usr/subBLOCK:SAPLKACB:1002/ctxtCOBL-AUFNR").text = "300336"
session.findById("wnd[0]/usr/sub:SAPMM07R:0521/ctxtRESB-MATNR[0,7]").text = "503027"
session.findById("wnd[0]/usr/sub:SAPMM07R:0521/txtRESB-ERFMG[0,26]").text = "306"
session.findById("wnd[0]/usr/sub:SAPMM07R:0521/ctxtRESB-LGORT[0,53]").text = "0048"
session.findById("wnd[0]/usr/sub:SAPMM07R:0521/ctxtRESB-LGORT[0,53]").setFocus
session.findById("wnd[0]/usr/sub:SAPMM07R:0521/ctxtRESB-LGORT[0,53]").caretPosition = 4
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[0]/btn[11]").press


Regards,
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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