#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 51
Default copy ?

Hi,

I have folder contains 10 to 15 excel file.


User want the data from any 3 files of that folder,


Any code that will display or pop up the open dialog box to select
the
3 files of that folder


and Three files data to be copied and to be pasted in new excel file.


Thanks in advance.


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 896
Default copy ?

this code will import data to worksheet "SOME_NAME" from worksheet
"ANY_NAME", in "fname" file, located in "path" directory, adjust
ranges to suit
hope I didn't mess up with any arguments
let me know if you have any problems

Sub pick_file()

ChDir "your_directory"

Set fd = Application.FileDialog(msoFileDialogFilePicker)
catalog = vbNullString


With fd
..AllowMultiSelect = False
..Filters.Clear
'.Filters.Add "Excel files", "*.xls", 1
..InitialView = msoFileDialogViewList
..Title = "PICK A FILE"
..Show
End With



fname = Application.FileDialog
(msoFileDialogFilePicker).SelectedItems.Item(1)

For i = Len(fname) To 1 Step -1
If Mid(fname, i, 1) = "\" Then
path = Left(fname, i)
fname= Right(fname, Len(fname) - i)
Exit For
End If
Next i


sht_name = "ANY_NAME"


'range to be imported is X17:AF17, range to be populated with data is
B23:J23
'ADJUST BOTH TO SUIT
For c = 24 To 32
celll= Cells(17, c).Address
Sheets("SOME_NAME").Cells(23, c - 22) = GetValue(path, fname,
sht_name, celll)
Next c


End Sub

where GetValue is:

Public Function GetValue(path, fname, sht_name, celll)
' Retrieves a value from a closed workbook
Dim arg As String

' Make sure the path exists
If Right(path, 1) < "\" Then path= path& "\"
If Dir(path& fname) = "" Then
GetValue = "path Not Found"
Exit Function
End If

' Create the argument
arg = "'" & path & "[" & fname & "]" & sht_name & "'!" & Range
(celll).Address(, , xlR1C1)

' Execute an XLM macro
GetValue = Application.ExecuteExcel4Macro(arg)
End Function


On 24 Mar, 15:14, wrote:
Hi,

I have folder contains 10 to 15 excel file.

User want the data from any 3 files of that folder,

Any code that will display or pop up the open dialog box to select
the
3 files of that folder

and Three files data to be copied and to be pasted in new excel file.

Thanks in advance.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
move or copy sheets doesn't copy format ColinX Excel Worksheet Functions 1 May 14th 08 10:07 PM
Copy and paste versus copy and insert copied cells Alana New Users to Excel 1 September 28th 07 08:58 PM
I copy a formula and the results copy from the original cell brooklynsd Excel Discussion (Misc queries) 1 June 23rd 07 01:35 AM
Copy/Paste how to avoid the copy of formula cells w/o calc values Dennis Excel Discussion (Misc queries) 10 March 2nd 06 10:47 PM
EXCEL FILE a copy/a copy/a copy ....filename ve New Users to Excel 1 September 29th 05 09:12 PM


All times are GMT +1. The time now is 04:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"