How to copy/paste a file from external file into a worksheet..

[Closed]
Report
Posts
1
Registration date
Wednesday October 10, 2012
Status
Member
Last seen
October 10, 2012
-
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
-


I have a problem of copying excel into new file.

I have a browser which takes an excel file and puts it into a text-box. Then I have a second button which loads that excel file into a new sheet.
My main problem is that when I put the excel file into a new sheet, it opens the older file, that I don't want to get opened.

Here is my code :

Public fileStr As String Sub GetOpenFile()
fileStr = Application.GetOpenFilename() Worksheets("Sheet2").TextBox1.Value = fileStr

End Sub

Sub Button3_Click__()
Dim wbk1 As Workbook, wbk2 As Workbook
Set wbk1 = ActiveWorkbook
Set wbk2 = Workbooks.Open(fileStr)
wbk2.Sheets(1).Cells.Copy wbk1.Worksheets("Sheet1").Cells(1, 1)

End Sub

In Short I want to remove this code :

Set wbk2 = Workbooks.Open(fileStr)

And put new code which will read a file , but not open it

1 reply

Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
768
you have to make connection to the file to do that