any clue? O_O....cause I am lost :S
Re: Open and LOGON on SAP with Excel Macro
Macro said I am log in SAP, but actually not the case...
Hi,
I have this macro that work and tell me that i sucessfuly log on in SAP.
Dim sapConn As Object 'Declare connection object 'added Set objshell = CreateObject("WScript.Shell") Set objapp = objshell.Exec(Environ("PROGRAMFILES") & "\SAP\FrontEnd\SAPgui\saplogon.exe") Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object 'Specify user sapConn.Connection.User = "Flie" 'Then password sapConn.Connection.Password = "Mz123" 'Client sapConn.Connection.Client = "100" 'added sapConn.Connection.System = "PVE" 'Target server address sapConn.Connection.ApplicationServer = "10.169.555.233" 'Language code sapConn.Connection.Language = "EN" If sapConn.Connection.Logon(0, True) <> True Then MsgBox "Cannot Log on to SAP" 'Issue message if cannot logon Else MsgBox "Logged on to SAP!" End If
When it open SAP...I still need to click logon and input my password and user name..
any clue? It seem there is no conenction between the two
Upload several documents SAP
Hello experts,
I am devolping a code to automate the solped creation process (particulary in proyects) (me51n) however i have reached an impass, because acoording to the enterprice rulebook we must upload: Licitacion basis, planes, formats, and other word files.
Is there a way that I can specify only the folder name and that every file contained is uploaded?
SAP logON connection not found error.
I get SAP Logon connection not found error 1000 when i run this into excel. any help?
Set SAPGUIApp = CreateObject("Sapgui.ScriptingCtrl.1") Set SapGuiConn = SAPGUIApp.OpenConnection(".vcm global production", True) Set Session = SapGuiConn.Children(0) Session.TestToolMode = 1 'added part to deal with sap status (open/close) Set log_opt = Session.FindById("wnd[1]/usr/radMULTI_LOGON_OPT2", False) If Not log_opt Is Nothing Then log_opt.Select Session.FindById("wnd[1]/tbar[0]/btn[0]").Press End If
EXCEL VBA Vs SAP: Copy text from textbox to LongText in SAP- Hash sign #
After a year hello again.
Im here to ask You for help. Today I hope it is quite simple, but Im stuck...:
I have automation on sending data from excel - textbox- to orders LongTexts in -SAP. Im using CO02.
Now the problem is when it copy the text into window in SAP it is ok - the same - I save the order change. When I open it again and go to the given longtext, there are many # signs on ends of lines.
I figured out that when it copy data from Textbox to SAP box window - text is the same but there are tabs or spaces on the ends of lines.... when I click on the end of some line, cursor jumps "Tab/Space" after text end. When I delete these spaces, hash signs disappear. The paragraph function in excel does not shows any spaces.
Hope the problem is described understandable. Can send screens it would be immediately clear.
Can someone propose a formatting to EXCEL BOX text or SAP LONGTEXT window?
Thanks in advance.
Mirek.
Re: Order Group import file
Hi Luc,
I have the same problem. Anybody know how to upload IO grop directly from excel file ( txt format)?
should be there special column sequene or sth?
rgs
M
Message box if sap session is not open
Hi SAP Experts,
I am new to SAP Vbscript. I have created a vbscript in SAP. My scripts extract the data from FBL1N and save it into a folder as .xls formate. Before run this VBscript I have to open SAP session.
So I would like to edit one message box in to my VBscript. This message box should warn If any user run this Vbscript before opening SAP session.
The messaage should be like (Please open SAP Session).
Here is my script:-
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
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "fbl3n"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtSD_SAKNR-HIGH").setFocus
session.findById("wnd[0]/usr/ctxtSD_SAKNR-HIGH").caretPosition = 0
session.findById("wnd[0]/usr/btn%_SD_SAKNR_%_APP_%-VALU_PUSH").press
session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL-SLOW_I[1,0]").text = "40305120"
session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL-SLOW_I[1,1]").text = "40305130"
session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL-SLOW_I[1,1]").setFocus
session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL-SLOW_I[1,1]").caretPosition = 8
session.findById("wnd[1]").sendVKey 8
session.findById("wnd[0]/usr/ctxtSD_BUKRS-LOW").text = "2350"
session.findById("wnd[0]/usr/ctxtPA_STIDA").text = '02102014"
session.findById("wnd[0]/usr/ctxtPA_STIDA").setFocus
session.findById("wnd[0]/usr/ctxtPA_STIDA").caretPosition = 10
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]/mbar/menu[0]/menu[3]/menu[2]").select
session.findById("wnd[1]/usr/sub:SAPLSPO5:0101/radSPOPLI-SELFLAG[1,0]").select
session.findById("wnd[1]/usr/sub:SAPLSPO5:0101/radSPOPLI-SELFLAG[1,0]").setFocus
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxtRLGRAP-FILENAME").text = str & "\Consignment dump GP1.XLS"
session.findById("wnd[1]/usr/ctxtRLGRAP-FILENAME").caretPosition = 48
session.findById("wnd[1]").sendVKey 0
Could you please help on this.
Sorry for my poor englsih
Thanks & regards,
Pradeep
Re: EXCEL VBA Vs SAP: Copy text from textbox to LongText in SAP- Hash sign #
try replacing the linefeed, carriage return or CRLF characters with a space or empty string
Session.FindById("wnd[0]/usr/...").Text = Repalce(vbLF,,,xlsheet.cells(1,1))
vbLf = linefeed only
vbCr = Carriage Return only - this one is definitely is good for the text boxes on text tabs on a PR or Delivery Doc
vbCrLF = CR and LF combined
Try each one individually to see which one is causing the problem and which one you can leave in to keep your line wrapping on the SAP side. I didn't test out in the prod order (CO02) long description box specifically. It seems that different long text boxes can act differently
Script to tell if document has an attachment in SAP
I would like to write a script to check if our MIRO and FB60 documents have an attachment. I would prefer a system report, but our IT group has not been able to provide this. I have reverted to writing a script that pulls up each invoice, opens up the attachment list window and then checks to see if there is an attachment. My script is not great because if there is no attachment, I don't know how to cleanly determine this. Right now I try to select the first attachment.
session.FindById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").selectedRows = "0"
If there is no attachment, I get an error message. In Excel I set up the error handler to jump to a part of the macro that records "no attachment", if there isn't an error message I record "has attachment".
Is there a cleaner way to do this?
Also, I'm checking thousands of these documents and if there is a warning message at the bottom of a window when I pull up the document with FBV3 (document deleted etc) then my macro falls over. Any ideas on how to handle messages in a general way?
Thanks,
Tyler
Re: Script to tell if document has an attachment in SAP
I use this technique to see if something exists or not to get ahead of it actually failing when you try to reference an object id that did show up as expected.
This example is looking to see if a new window popped up with the serial nbr grid entry in it. Not just any new window (that would be just wnd[1]), but specifically down to a field I expect to see on it, so I know it's not some other window I haven't seen before.
Set SAPobj = SAPSession.FindById("wnd[1]/usr/tblSAPLIPW1TC_SERIAL_NUMBERS/ctxtRIPW0-SERNR[0,0]", False)
If SAPobj Is Nothing Then
MsgBox ("Serial Nbr provided but part is not serialized. Order was not created. Skipping record")
Exit Function
Else
'do good things
End If
I use this technique to check for warning messages and press enter to acknowledge
I know there is a way to check if the type of message is a warning vs hard stop error and I considered just checking for that but it's handy to know what kind of warnings I have already accounted for so I still code it to look at the specific text.
'check for not a working day warning and press Enter key to acknowledge
If InStr(GetSAPStatus(), "not a working day") > 1 Then
SAPSession.FindById("wnd[0]").SendVKey 0
End If
GetSAPStatus is a custom function:
Function GetSAPStatus()
On Error Resume Next
GetSAPStatus = ""
GetSAPStatus = SAPSession.ActiveWindow.FindByName("sbar", "GuiStatusbar").Text
On Error GoTo 0
End Function
How to return the window/screen name in GUI scripting
I'm starting out with SAP GUI scripting. I'm driving the scripts from Excel, which works well. I haven't found a reference book that explains the objects, methods and properties available in SAP GUI scripting so I do a lot by trial and error, guessing at what I think the property might be. One of the issues that I have run into is that when I look up a document using FBV3, the resulting screen can be different. I don't understand what is driving the difference (vendor type, document type, company code ???). I need to grab a field off of the window, but the field will be referenced different depending on the type of window that come up.
Is there a way with GUI script to read the name of the window so that I know which field reference to use to get the field that I want?
Thanks,
Tyler
Re: Start recording directly from Excel
Regarding your comment: "...Or store each recorded line as Excel-row. With change-method we can adjust recored lines before it will store as file....."
Can you please give me more information on how to capture each recorded line and write it to excel?
Re: How to return the window/screen name in GUI scripting
Hello.
session.findById("wnd[0]").Name
Or if you have a Dialog popup it can be:
session.findById("wnd[1]").Title
Best regards,
Holger
Re: Script to tell if document has an attachment in SAP
Thanks Chad. I'm trying to implement your code, but the SAP script I recorded doesn't give me an object that I can address. It shows as the following:
' this bit opens up the attachment list window
session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"
session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_VIEW_ATTA"
' this is what happens when I click on the first attachment
session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").currentCellColumn = "BITM_DESCR"
session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").selectedRows = "0"
I tried to use session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").Rows(0) as the object, but it isn't working. (Object doesn't support this property or method). Can you see what I'm doing wrong? Ideally I would like to see if there is an attachment, or even better, read how many items are attached.
Is there a way within SAP to see what objects are in each window and what methods and properties are associated with each object?
Thanks,
Tyler
Re: Message box if sap session is not open
Hi Pradeep,
you can try the following:
on error resume next
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
myError = err.number
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
myError = err.number
End If
on error goto 0
if myError <> 0 then
msgbox "Please open SAP Session.", vbinformation, "Note"
else
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
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "fbl3n"
. . .
session.findById("wnd[1]").sendVKey 0
end if
Regards,
ScriptMan
SAP GUI Scripting trying to paste screenshot of SAP to excel sheet(HardcopyToMemory)
Dear Experts,
I have been trying to access the clipboard for screenshot of SAP copied through "session.findById("wnd[0]").HardcopyToMemory" and pasting the same in an Excel Sheet.
I have been trying the same for last two weeks unsuccessfully.
Requesting for your Kind help if someone have already addressed this issue.
Please let me know if i have to furnish some more details..
Regards,
Kumar Santharam
Re: SAP GUI Scripting trying to paste screenshot of SAP to excel sheet(HardcopyToMemory)
Hello.
Shortest way is copy Picture as file and insert into Excel from file. After this is done delete created file.
With some smart code using shapes you can Position Pictures on sheet.
Sub image_sap() If Not IsObject(Applic) Then Set SapGuiAuto = GetObject("SAPGUI") Set Applic = SapGuiAuto.GetScriptingEngine End If If Not IsObject(Connection) Then Set Connection = Applic.Children(0) End If If Not IsObject(session) Then Set session = Connection.Children(0) End If session.findById("wnd[0]").HardCopy "C:\tmp\test.jpg", 1 ActiveWorkbook.ActiveSheet.Pictures.Insert "C:\tmp\test.jpg" Kill "C:\tmp\test.jpg" End Sub
Re: SAP GUI Scripting trying to paste screenshot of SAP to excel sheet(HardcopyToMemory)
Thanks alot Holger for sharing this cool piece of code... This has addressed my issue...
In the meanwhile can u please shed some light into when really we have to use the "session.findById("wnd[0]").HardcopyToMemory" code...
Re: SAP GUI Scripting trying to paste screenshot of SAP to excel sheet(HardcopyToMemory)
Hello. In SAP Scripting Help file (CHM) you can find this Piece of code:
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 Image = session.findById("wnd[0]").HardCopyToMemory() Const adTypeBinary = 1 Const adSaveCreateOverWrite = 2 Dim BinaryStream Set BinaryStream = CreateObject("ADODB.Stream") BinaryStream.Type = adTypeBinary BinaryStream.Open BinaryStream.Write Image BinaryStream.SaveToFile "C:\screenshot.bmp", adSaveCreateOverWrite MsgBox "Done"
With some API-functions you should also be able to read Image from Memory and paste in Excel sheet. But first Piece of code is much smaller.
Re: SAP GUI Scripting trying to paste screenshot of SAP to excel sheet(HardcopyToMemory)
Hi Holger,
Thanks again for sheding some light on the 'HarcopyToMemory' code...
Have a Great day ahead,
Kumar Santharam