vba - How to copy data from another workbook (excel)? -


I already have a macro that creates sheets and some other stuff. Made after a sheet, I want to call another macro which copies the first and active excel file to the second excel (its open) data.

First I want to copy the header, but I do not get it to work - get errors.

  Sub-copy (sheet name as string) in the form of a slow file string, in the form of Sheetadata string file = "My file. Xls" SheetData = "Name of the sheet where the data is" main Copy the file into sheets in the workbooks (file). "Worksheets. (Sheetadata) .Range (" A1 "). # Select: Failure here: Method selection for class category workbooks (file) failed. Worksheet (Sheetadata ) .reak (selection, selection. End (xlToRigh) Select the workbook (SheetData) Select Copy ActiveWorkbook.Sheets (sheetName). Game (1, 1) End Sub  

What's wrong? < / P>

I really want to avoid activating "my file .xls".

EDIT: I had to give it and copy sheet data to target as a target New Sheet, before it can work

Two years later (on Google it has been found, Therefore someone else To) ... As mentioned above, you do not need to select anything. These three lines:

Workbooks (file). Worksheet (range of "A1"). Select Workbook (File). Worksheet (range). Ranges (Selection, Selection (XLTORIT)). Select Workbook (File). Worksheet (Sheetadata) Selection. Copy ActiveWorkbook.Sheets (sheetName) .mail (1, 1)

may be

replaced with workbooks (file). Worksheet (Sheetadata) .Renz (Workbook), Worksheet (Sheetadata). _ Range ("A1"), Workbook (File) Worksheets (Sheetadata) .Renze ("A1"). End (XLTORIT) Copy _ Destination: = Active Directory Book Sheets (Sheetem) .seel (1, 1)

This selection should be around error


Comments