transfering data from file to file using vba

arian29

In the zone
I need to copy a set of data from one excel file to anoter. I am writing the code (vba) in file A and need to copy the data from file B to file A. I wrote the below code, its opening the file B and copying it but is not pasting it in file B which i open already. Need help...

Function transfer()

Dim wbk As Workbook

FirstFile = "D:\P.xls"
FinalFile = "D:\late.xlsm"

Set wbk = Workbooks.Open(FirstFile)
With wbk.Sheets("CIP")

Range("A2:A90").Select
Selection.Copy

End With

Set wbk = Workbooks.Open(FinalFile)
With wbk.Sheets("All data")
Range("A2").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

End With

End Function
 

krishnandu.sarkar

Simply a DIGITian
Staff member
Well, I'm not 100% sure, but I think open the FinalFile with diff. variable that FirstFile. As far I think coping it doesn't copies to clipboard and then paste from there, as clipboard is a program which is written by OS Manufacturer to make our job easy.

So say for opening FinalFile don't use wbk rather declare another variable, say wbkfinal and use it to open FinalFile workbook.
 
Top Bottom