cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Copy/Paste Macro from SAP to Excel

Former Member
0 Kudos

I'm newer to VBA and SAP. Basically I'm using a transaction in SAP that pulls an income statement for multiple business segments so it has multiple income statements. Currently I'm copying and pasting each income statement one by one into excel. Is it possible to create a macro that will do this for me and if so how? Right now when I create a macro the code will show the cells that I select and then copy and then the cell that a select and then paste. There is nothing in the code that tells it to switch over to an excel file before it pastes; thats the part I'm stuck at. Please keep in mind that I'm just coming into learning VBA so I'm by no means an expert. Thanks.

P.S. I know there are other similar threads to mine and I have looked through a bunch of them but since I'm so new to all of this I'm having a little bit of a hard time with some of the terminology/answers.

Edited by: bearsfan216 on Aug 29, 2011 2:55 AM

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi

Sorry to bother you but i have seen peole getting extreme support.

I want to copy all the columns  at the end of a vb script (running ME2M, with ALV grid).

When I try to record CTRL+V, it does not work. You have hhelped someone already with that and I am unable to find it.

It would be of enormous help if you could tell me what is vb script code for copying data in SAP.

PS: I am new to the community so did not know how to approach you.

ANYONE else who knows the method, please do help me!

thomas_brutigam2
Active Participant
0 Kudos

Hi bearsfan,

if you could show us some of your code thats allready done

i'm sure we could help

If you mean by "switching to excel" that ExcelSheet is activated (or selected)

thats done by the Objects in VBA

For example:



'Here is a Code that "copies" some SAP-Textboxes to Excel

Set sht = "Tabelle1"
With sht
     .Cells(1,1).Value = session.findbyid("wnd[0]/usr/cTxt...").Text
     .Cells(2,1).Value = session.findbyid("wnd[0]/usr/txt").Text
end with
set sht = nothing

First line in Example sets a Object to a existing Worksheet (a Workbook has to be open!!!)

Second line only Shortens up things a little

in third and fourth line the Value of any Textbox in Sap is written to Excel

of course this has to be modified to your settings ...

other Things are just VBA in Excel -

Press F1 for help

Greetings

Thomas Br

Former Member
0 Kudos

Here is what I currently had. There are mulitple folders in the report that I pull up so bascially I am trying to copy B2:C16 from each of the different folders but after I copy the first folder over and switch back to SAP I don't know how to write the code to switch to the next folder and then copy B2:C16 and so forth

Range("B2:C16").Select

Selection.Copy

AppActivate ("Microsoft excel - book1")

Range("B2:C16").Select

ActiveSheet.Paste

AppActivate ("E-Report PCA")

Range("B2:C16").Select

Selection.Copy

AppActivate ("Microsoft excel - book1")

Range("D2:E16").Select

ActiveSheet.Paste

End Sub

thomas_brutigam2
Active Participant
0 Kudos

Hi bearsfan,

I think i need more Input of yours

How (and where) are you "pasting" the Excel Values to SAP ?

If you could show us that please ?

by the way Don't use App-Activate !

or do you start SAP by using Shell or ShellExecute ?

Then youre totaly wrong

by the way

what do you mean by different folders ?

more Workbooks ? (I only hope so...)

Greets

Thomas Br

Former Member
0 Kudos

I'm trying to copy from sap to excel, not the other way around. I have SAP in the excel format so I am able to start my macro within SAP, so it is copying data from SAP just like it would in excel and then switches to my excel workbook and pastes it there.

The other folders that I mentioned are basically this: I am running an income statement for my whole company but its broken down by different entities so there is an income statement for each entiity. So on the left side of the screen in SAP there are all the different entities listed that I can click on and once I click on it it populates my SAP screen with the new data.

So bascially I am able to copy and paste from SAP to excel but the one thing I can't figure out is switching to the next entity so my SAP screen populates the different numbers, so then I can paste the next entity to my excel and so forth.

Also the reason why I'm using App.Activate is because it was the easiest thing for me to rap my head around for switching between programs. Basically I'm trying to keep it as simple as possible even if its not the most efficient way. And I'm not using anything to open SAP. The actual task for get to the SAP data I need is done manually because I don't want to bother using a macro for that because I can do it manually very easily.

Former Member
0 Kudos

Even if there were some coding where the macro would pause itself, then I could click on the next folder, and once I clicked to the next folder the macro would resume would work for me. If that is possible that would solve my final problem.

Former Member
0 Kudos

Hi:

If you're open to using another methodology than VBA, you might try automation software to record your copy/paste to Excel actions into a task that you can schedule and run. Would probably save you time. Let me know if you want more info.

I had a hard time responding to this one, since I'm a Packer fan

Hope this helps.

Tom