Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
EA EA is offline
external usenet poster
 
Posts: 12
Default Is transfer data from one Excel file to another possible?

I have a named range in my €˜FileA.xls file that references an array of data.
But say if Im working in €˜FileB.xls and €˜FileA.xls is closed, is there
any way in VB to call out and import the named range from €˜FileA.xls into
€˜FileB.xls?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 229
Default Is transfer data from one Excel file to another possible?

You'd have to open FileA.xls - this code, placed in a module of
FileB.xls, will open FileA.xls (or use it if it's already opened), use
a range called "NamedRange", and copy its content to Sheet2 in
FileB.xls, starting on A1. If FileA.xls is already open, it will
still perform the copy, but will not close the file.

Public Sub ImportNamedRange()
Dim rng As Excel.Range
Dim wkb As Excel.Workbook
Dim blnClose As Boolean

Const strName As String = "NamedRange"

blnClose = False
Set rng = ThisWorkbook.Sheets("Sheet2").Range("A1")

On Error Resume Next
Set wkb = Application.Workbooks("FileA.xls")
If Err.Number < 0 Then
Set wkb = Application.Workbooks.Open("FileA.xls")
blnClose = True
Err.Clear
End If
On Error GoTo 0

wkb.Names(strName).RefersToRange.Copy _
ThisWorkbook.Sheets("Sheet2").Range("A1")

If blnClose Then wkb.Close (False)
End Sub



I can't think of a simpler way to do this.


On Oct 18, 4:46 pm, EA wrote:
I have a named range in my 'FileA.xls' file that references an array of data.
But say if I'm working in 'FileB.xls' and 'FileA.xls' is closed, is there
any way in VB to call out and import the named range from 'FileA.xls' into
'FileB.xls'?



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 229
Default Is transfer data from one Excel file to another possible?

Replace this:

wkb.Names(strName).RefersToRange.Copy _
ThisWorkbook.Sheets("Sheet2").Range("A1")


with this:

wkb.Names(strName).RefersToRange.Copy rng


On Oct 19, 1:21 am, iliace wrote:
You'd have to open FileA.xls - this code, placed in a module of
FileB.xls, will open FileA.xls (or use it if it's already opened), use
a range called "NamedRange", and copy its content to Sheet2 in
FileB.xls, starting on A1. If FileA.xls is already open, it will
still perform the copy, but will not close the file.

Public Sub ImportNamedRange()
Dim rng As Excel.Range
Dim wkb As Excel.Workbook
Dim blnClose As Boolean

Const strName As String = "NamedRange"

blnClose = False
Set rng = ThisWorkbook.Sheets("Sheet2").Range("A1")

On Error Resume Next
Set wkb = Application.Workbooks("FileA.xls")
If Err.Number < 0 Then
Set wkb = Application.Workbooks.Open("FileA.xls")
blnClose = True
Err.Clear
End If
On Error GoTo 0

wkb.Names(strName).RefersToRange.Copy _
ThisWorkbook.Sheets("Sheet2").Range("A1")

If blnClose Then wkb.Close (False)
End Sub

I can't think of a simpler way to do this.

On Oct 18, 4:46 pm, EA wrote:



I have a named range in my 'FileA.xls' file that references an array of data.
But say if I'm working in 'FileB.xls' and 'FileA.xls' is closed, is there
any way in VB to call out and import the named range from 'FileA.xls' into
'FileB.xls'?- Hide quoted text -


- Show quoted text -



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
I want to transfer a data base file into Excel then do mail merge Jan Excel Discussion (Misc queries) 3 July 7th 06 08:58 PM
how do i transfer an excel file from one computer to another ddeever Excel Worksheet Functions 2 December 21st 05 09:09 PM
How can I transfer a Lotus 123-9 data spread sheet file to Excel? EDECHO Setting up and Configuration of Excel 2 August 26th 05 11:23 PM
How do I transfer data in a pdf file into an excel workbook? CBooze1969 Excel Discussion (Misc queries) 2 April 19th 05 04:18 PM
PDF or Image file transfer to Excel Neutron1871 Excel Discussion (Misc queries) 1 March 23rd 05 10:45 PM


All times are GMT +1. The time now is 11:51 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"