Workbook won't open from SAP unless macro stops

RodrigoFinguer

Board Regular
Joined
Jun 13, 2017
Messages
75
Hello!!

I am really having trouble with this issue here.

This is my code:

Code:
Sub sap_attachment_2()
'anexos na lista de anexos

Set SapGuiAuto = GetObject("SAPGUI")
   Set SAPApplication = SapGuiAuto.GetScriptingEngine
   Set SAPConnection = SAPApplication.Children(0)
   Set session = SAPConnection.Children(0)
   
   Application.EnableEvents = False

session.findById("wnd[0]").maximize
session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"
session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_VIEW_ATTA"

Set SAPattachs = session.findById("wnd[1]/usr/cntlGRID1/shellcont/shell")
session.findById("wnd[1]/usr/cntlGRID1/shellcont/shell").setCurrentCell 0, "BITM_DESCR"


count_files = SAPattachs.RowCount

Application.ScreenUpdating = True

For q = 2 To count_files - 1
Name = session.findById("wnd[1]/usr/cntlGRID1/shellcont/shell").getcellvalue(q, "BITM_DESCR")
session.findById("wnd[0]").maximize
session.findById("wnd[1]/usr/cntlGRID1/shellcont/shell").setCurrentCell q, "BITM_DESCR"
session.findById("wnd[1]/usr/cntlGRID1/shellcont/shell").selectedRows = q
session.findById("wnd[1]/usr/cntlGRID1/shellcont/shell").doubleClickCurrentCell

Application.Wait (Now + TimeValue("0:00:02"))


'Application.OnTime Now + TimeSerial(0, 0, 4), "Módulo4.movePDF"


movePDF
If hwnd <> 0 Then
closepdf
Else
End If

Next
End Sub

My code go to the SAP, opens the attachments list and double click the file to open from SAP. Then I get the file and move from "C:\Temp" to "myfolder", whatever folder is this.

The thing is that, when there is "xlsx" files to open from SAP, the workbook does not open unless I stop the macro or debug, this way I can't move the file from the Temp folder.

PS: I don't know how to make the code colorful to make easy to read.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

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