Hi,
This is my first post here, so I'm not totally sure this is the correct place - hopefully it is
I'm trying to find some script/code that I can use in an Excel macro to change the user's default number format from 1.000,00 to 1,000.00 for one thousand, and then to change it back after running my existing code. Some users are in the UK and will not need theirs changing (they will use 1,000.00), but other users in Europe will need theirs changing (they will use 1.000,00 but need theirs changing to 1,000.00, then changing back to 1.000,00 after my other separate macro has run).
The second part of the code (described below) takes the user to one of the menus, but stops at the "address" tab.
The third part should press the "default" tab, then change the "decimal notation" option, but does not - this is the area I would particularly like help with! I recorded the individual steps in SAP and obtained the code, but it doesn't seem to work within the macro - SAP doesn't seem to do anything
I don't think I recorded the step to "save" the changes - are you able to add some code for that and also to log the user out of that session of SAP (back to the main log in menu) so they log back in with the new settings (SAP's default seems to be to create a new session, which might get confusing..?)
When my separate macro has run, I would like to change the default number format back to whatever it was - some users are in the UK so their number format should not be changed. If it helps, I have a country code allocated on, say, Excel Sheet 1 and cell A1 which says UK or Europe.
Any help will be truly appreciated as I am struggling with this!!!
Thanks,
Graham
Sub change_number_format()
'1st part of the code - tell Excel about SAP
On Error GoTo errhandler
If Not IsObject(SAP_Application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAP_Application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SAP_Application.Children(0)
End If
On Error Resume Next
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject SAP_Application, "on"
End If
On Error Resume Next
'2nd part of the code - this code takes the user part of the way
session.findById("wnd[0]").maximize
session.findById("wnd[0]/mbar/menu[4]/menu[2]/menu[3]").Select
session.findById("wnd[0]/mbar/menu[2]").Select
'3rd part of the code - this code was recorded in individual steps in SAP to perform the required actions, but doesn't seem to work as part of the script
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpDEFA").Select 'move to the second tab
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpDEFA/ssubMAINAREA:SAPLSUID_MAINTENANCE:1105/cmbSUID_ST_NODE_DEFAULTS-DCPFM").Key = "" 'change number format
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpDEFA/ssubMAINAREA:SAPLSUID_MAINTENANCE:1105/cmbSUID_ST_NODE_DEFAULTS-DCPFM").SetFocus 'change number format
Exit Sub
'4th part of the code - error handling (user isn't logged in)
errhandler:
MsgBox "Please log into SAP then click the 'Update/Refresh SAP data' button again"
Exit Sub
End Sub