Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

copying and pasting different

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Copying and pasting from a different workbook

Copying and pasting from a different workbook

ResolvedVersion 2010

Freddie has attended:
Excel VBA Introduction course

Copying and pasting from a different workbook

Hi Guys

Firstly, many thanks for your response on my other question -it worked a treat!

I've come up against another obstacle though in my macro.

I'm trying to copy and paste from another workbook, but my code is incorrect - are you able to help?

The file path where I want to copy from is:

C:\Users\Desktop\Macro Project\52 CCY + Market for Static Data Checks.xlsx"
Cells.Select
Range("A1:B212").Copy

And the file I want to paste to is a worksheet called "BBA" in the below path: (in cell A312)
C:\Users\Desktop\Macro Project\MacroTes3.xls")

Are you able to assist?
Thanks!
Freddie

RE: Copying and pasting from a different workbook

Hi Freddie,


Thank you for the forum question.

Please copy and paste the code below to a module in the destination workbook.

Sub CopyFromAnotherWorkbook()

''''''The code below is if the source workbook is not open.


Dim WkBook As Workbook

''''''will open the source workbook. You will need your own path below.
Set WkBook = Workbooks.Open("C:\Users\Admin\Desktop\EMPLOY4.xlsx")

''''' You will need to change the sheet name and range in thee line below (the sheet and range in the source workbook).
ActiveWorkbook.Sheets("Employees").Range("a5:g33").Copy

ThisWorkbook.Activate

Sheets(1).Range("b2").Select

'''''''' paste is an activesheet member
ActiveSheet.Paste

'''''will empty the clipboard
Application.CutCopyMode = False


WkBook.Close savechanges:=False




End Sub


I hope this is what you are looking for but please let me know if you have any problems.


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Removing custom dictionary entries

If you add something to the custom dictionary in Excel you cannot remove it. The way to get around this is to go into word and remove it there.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.