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

Closed
Zamani Posts 1 Registration date Wednesday October 10, 2012 Status Member Last seen October 10, 2012 - Oct 10, 2012 at 05:03 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Oct 10, 2012 at 02:38 PM


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
Related:

1 response

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Oct 10, 2012 at 02:38 PM
you have to make connection to the file to do that
0