DIGIT-ARC read-only archive · snapshot: July 23, 2026

transfering data from file to file using vba

2 posts · originally from https://geek.digit.in/community/threads/transfering-data-from-file-to-file-using-vba.140719/

A
arian29 Original post #1
May 13, 2011 at 6:06 PM
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
May 13, 2011 at 6:36 PM
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.