Hello,
I am trying to copy some values from a workbook that is not open and paste them into the active workbook that contains the macro. Though it sounds relatively easy, I cannot do it.
The problem seems to be when pasting the values, at the last line of my code. I keep receiving the following message : "Run time error 438 Object doesn't support this property or method".
The code that I have written is the following:
Do I need to change the entire structure or could I do sth simpler to make that work?Sub copy_service_scores() ' ' Dim s_file As String 'defintion of the source file variable Dim t_file As String 'defintion of the target file variable s_file = "full path.xls" Workbooks.Open s_file Sheets("sheet name").Select Range("D10:E37").Select Selection.Copy Windows("the name of the workbook that is already open and contains the macro .xlsx").Activate Sheets("Sheet1").Select Range("D10").Select Selection.Paste End Sub
Thanks and regards,
Ilias
Last edited by Ilias1987; 02-05-2012 at 05:03 PM. Reason: add code tags PM rules
You could use
Sub test() Set wb = ActiveWorkbook.Worksheets("Sheet1") ' This the workbook which is open where you want to paste Workbooks.Open("c:\ttt\Book1.xlsx").Worksheets("Sheet1").Range("D10:E37").Copy ' change to the path of the book you want to copy from wb.Range("D10").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False End Sub
Hope this helps.
Anthony
Pack my box with five dozen liquor jugs
PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated”
Thanks for the tip smuzoen!
Now the problem is that I have 100 different closed book (let us say book_1 ... book_100) and I want to copy the data from an identical sheet in each of these workbooks (let us say that the name of this sheet will be always common_sheet). This data will be pasted in 100 different sheets inside the active workbook.
The process I had in mind was
However, now I don't know how to combine that logic when using the path to open each closed sheet.For x = 1 to 100
copy data from book_x common_sheet
paste data into active_workbook sheet_x
Next x
Any ideas please??
Thanks in advance
Ilias
I found a way to do it, by the following code
Now I am getting this messageSub copy_paste ()
For x = 1 To 100
target_ws = "Sheet" & x
source_wb = "file path" & x & ".xls"
Set wb = ActiveWorkbook.Worksheets(target_ws)
Workbooks.Open(source_wb).Worksheets("Serv").Range("B2:K37").Copy
wb.Range("B2").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Set wb2 = ActiveWorkbook
wb2.Close SaveChanges = False
Next x
End Sub
"There is a large amount of information on the clipboard. Do you want to paste this information into another program later... "
at the end of each loop, when reachingAny additional code to get rid of that message while running the macro? I don't want to have this data available later!wb2.Close SaveChanges = False
Kr
Ilias
Hello Ilias1987,
I have added a line to the macro that will clear the clipboard after the workbook is closed.
Sub copy_paste () For x = 1 To 100 target_ws = "Sheet" & x source_wb = "file path" & x & ".xls" Set wb = ActiveWorkbook.Worksheets(target_ws) Workbooks.Open(source_wb).Worksheets("Serv").Range("B2:K37").Copy wb.Range("B2").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Application.CutCopyMode = False Set wb2 = ActiveWorkbook wb2.Close SaveChanges = False Next x End Sub
Last edited by Leith Ross; 02-05-2012 at 04:15 PM.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Thanks again,
How can I marked it as solved? Is that an option in some sort of menu or just type [SOLVED] in a new post? Sorry for asking, I m new to the forum
Hello Ilias1987,
How to mark a thread Solved
Go to the first post
Click edit
Click Go Advanced
Just below the word Title you will see a dropdown with the word No prefix.
Change to Solved
Click Save
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks