Hi All,
I am new to this forum.
Can anyone help me in writing a macro code for Opening a excel sheet and copy the data in it and close the file???
Hi All,
I am new to this forum.
Can anyone help me in writing a macro code for Opening a excel sheet and copy the data in it and close the file???
this macro opens file, copy sheet1 on sheet2, closes the file
![]()
Sub Open_File_Copy_to_Sheet() Dim fd As FileDialog, SelFile Set fd = Application.FileDialog(msoFileDialogFilePicker) Set wb = ActiveWorkbook If fd.Show = -1 Then SelFile = fd.SelectedItems(1) ActiveCell.Value = SelFile Workbooks.Open Filename:=SelFile End If Set fd = Nothing Set wb1 = ActiveWorkbook ActiveSheet.Copy wb.Sheets(2) wb1.Close End Sub
If solved remember to mark Thread as solved
Thanks for your reply.
But I need that to be copied to a new file....
Hi, girish1989,
maybe try something like this (there´s still some information from your side missing (save to which name, xlFileFormat and where to save):
Ciao,![]()
Sub Open_File_Copy_to_NewWorkbookt() Dim fd As FileDialog Dim wbData As Workbook Set fd = Application.FileDialog(msoFileDialogFilePicker) If fd.Show = -1 Then Set wbData = Workbooks.Open(Filename:=fd.SelectedItems(1)) wbData.ActiveSheet.Copy With ActiveWorkbook .SaveAs Format(Now, "yymmdd_hhnnss") & "_test", FileFormat:=xlExcel8 .Close False End With wbData.Close False Set wbData = Nothing End If Set fd = Nothing End Sub
Holger
Use Code-Tags for showing your code: [code] Your Code here [/code]
Please mark your question Solved if there has been offered a solution that works fine for you
Thanks a lot
If that takes care of your original query, please select Thread Tools from the menu above and mark the thread as solved. Thanks.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc
?Actually, I *am* a rocket scientist.? - JB (little ones count!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks