Hi Friend,

What i understand is you want to copy data from source workbook to selected 
target workbook for this purpose i have written this macro just copy and 
paste the macro and run it and let me know if it is what you required.


Public Sub GetDataFromFiles()

    Dim intCtr      As Integer
    Dim strFiles    As String
    
    Dim wbkS        As Workbook
    Dim wbkT        As Workbook
    
    strSurce = Application.GetOpenFilename("*.xls,*.xlsx", , "Select Source 
Files", , False)
    If Not IsEmpty(strSurce) = False Then
        MsgBox "Please Select Source File..."
        Exit Sub
    End If
    
    strTarget = Application.GetOpenFilename("*.xls,*.xlsx", , "Select 
Target Files", , False)
    If Not IsEmpty(strTarget) = False Then
        MsgBox "Please Select Target File..."
        Exit Sub
    End If
    
    Set wbkS = Workbooks.Open(strSurce)
    Set wbkT = Workbooks.Open(strTarget)
    
    wbkS.Worksheets(1).UsedRange.Copy
    wbkT.Worksheets(1).Range("A1").PasteSpecial
    wbkT.Save
    wbkS.Close
    wbkT.Close
    
    Set wbkS = Nothing
    Set wbkT = Nothing
    
    MsgBox "Data has copied successfully."
    
End Sub





Regards
Prince dubey.


On Friday, November 9, 2012 11:55:42 PM UTC+5:30, Best Of Luck wrote:
>
> Hi,
>  
> I was using the code below to import data into a Excel 2010 workbook with 
> only one sheet. I now have multiple sheets and I wont this macro to only 
> import the data into the active sheet. Here is the code. 
>  
> Sub ImportCity()
> ' Get customer workbook...
> Dim customerBook As Workbook
> Dim filter As String
> Dim caption As String
> Dim customerFilename As String
> Dim customerWorkbook As Workbook
> Dim targetWorkbook As Workbook
> ' make weak assumption that active workbook is the target
> Set targetWorkbook = Application.ActiveWorkbook
> ' get the customer workbook
> filter = "Text files (*.xlsx),*.xlsx"
> caption = "Please Select an input file "
> customerFilename = Application.GetOpenFilename(filter, , caption)
> Set customerWorkbook = Application.Workbooks.Open(customerFilename)
> ' assume range is A1 - C10 in sheet1
> ' copy data from customer to target workbook
> Dim targetSheet As Worksheet
> Set targetSheet = targetWorkbook.Worksheets(1)
> Dim sourceSheet As Worksheet
> Set sourceSheet = customerWorkbook.Worksheets(1)
> targetSheet.Range("A8", "V100").Value = sourceSheet.Range("A8", 
> "V100").Value
> ' Close customer workbook
> customerWorkbook.Close
> End Sub
>

-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES (1120+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

6) Jobs posting is not allowed.

7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to excel-macros@googlegroups.com.
To unsubscribe from this group, send email to 
excel-macros+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros?hl=en.


Reply via email to