Prince thanks for the code. In Your code you are opening the target file. 
In my case the target file will already be open. I will have Sheet1, 
Sheet2, Sheet3, Sheet4 and so on. Every month I will open the spreadhseet 
to a new Sheet and run the data import. My code works but always imports 
the data in the first sheet  so I need a way to import it into the current 
sheet.
 
thanks in advance
On Friday, November 9, 2012 12:25:42 PM UTC-6, 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