dbTalk Databases Forums  

Problem using Excel named ranges within a DTS package

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Problem using Excel named ranges within a DTS package in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
dcrawley
 
Posts: n/a

Default Problem using Excel named ranges within a DTS package - 12-21-2006 , 05:41 AM






Hello

I am importing data from an Excel spreadsheet into a table, via DTS. I
am trying to use a named range in the spreadsheet, and have used a
script from Allan Mitchell to achieve this:-

' 243 (Excel Named Range)
Option Explicit

Function Main()

Dim sActualLocationOfData
Dim Excel_Application
Dim Excel_WorkBook
Dim Excel_WorkSheet
Dim oPkg
Dim oConn
Dim cus

' Location, which sheet and in which cells is our Data.
' This will produce a string like Sheet1!R14C8:R11C43

sActualLocationOfData = "=Sheet" &
CStr(DTSGlobalVariables("SheetNumber").Value) & _
"!" & DTSGlobalVariables("DataLocation").Value

' Create and set up the Excel File to Import
Set Excel_Application = CreateObject("Excel.Application")

' Open Excel Workbook
Set Excel_WorkBook =
Excel_Application.Workbooks.Open(DTSGlobalVariable s("FileLocation").Value)

' Get the Worksheet
Set Excel_WorkSheet =
Excel_WorkBook.Worksheets(Cint(DTSGlobalVariables( "SheetNumber").Value))

' Tell Excel where to get the data and add a named range to the
workbook.
' The DTS pump is expecting a source table of "ImportTable" so we name
our range that.
Excel_WorkBook.Names.Add "ImportTable", sActualLocationOfData

' Save the changes back to the workbook. If you fail to do this then
you will get
' a message box asking you if you want to make changes to the Excel
spreadsheet
Excel_WorkBook.Save

' Clean Up Excel Objects
Excel_WorkBook.Close
Set Excel_WorkBook = Nothing
Excel_Application.Quit
Set Excel_Application = Nothing


' Now set the Excel Filename on the Connection
Set oPkg = DTSGlobalVariables.Parent
Set oConn = oPkg.Connections("Excel File")

oConn.DataSource = DTSGlobalVariables("FileLocation").Value

' Clean Up DTS objects
Set oConn = Nothing
Set oPkg = Nothing

Main = DTSTaskExecResult_Success
End Function

The named range is created successfully, and saved to the Excel file.
My problem is that the Transform Data Task is not picking up the named
range, and so does not make it available in the dropdown list for
Table/View on the Source tab. I added some extra code, also from
Allan, as follows:-

Set oPkg = DTSGlobalVariables.Parent
Set cus= oPkg.Tasks("DTSTask_DTSDataPumpTask_1").CustomTask
cus.SourceObjectName = "ImportTable"

however, this through an error on the Transform Data Task, saying that
it couldn't find 'ImportTable'.

Is there something obvious that I'm doing wrong? Like I say, it is
creating the named range ok, it's just that the data pump task is
refusing to acknowledge its presence. My global variables for file
location, data, etc., are also correct, as far as I can see.

Any help would be appreciated

Thanks

Denise


Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Problem using Excel named ranges within a DTS package - 12-22-2006 , 04:49 AM






OK so with the Named Range created if you drop on an Excel Connection to
designer. and try to move data from it to somewhere else then the named
range does not appear?



--


Regards



Allan Mitchell


Konesans Ltd
T +44 7966 476 572
F +44 2071 008 479
http://www.konesans.com


"dcrawley" <denise.crawley (AT) hymans (DOT) co.uk> wrote


Quote:
Hello

I am importing data from an Excel spreadsheet into a table, via DTS. I
am trying to use a named range in the spreadsheet, and have used a
script from Allan Mitchell to achieve this:-

' 243 (Excel Named Range)
Option Explicit

Function Main()

Dim sActualLocationOfData
Dim Excel_Application
Dim Excel_WorkBook
Dim Excel_WorkSheet
Dim oPkg
Dim oConn
Dim cus

' Location, which sheet and in which cells is our Data.
' This will produce a string like Sheet1!R14C8:R11C43

sActualLocationOfData = "=Sheet" &
CStr(DTSGlobalVariables("SheetNumber").Value) & _
"!" & DTSGlobalVariables("DataLocation").Value

' Create and set up the Excel File to Import
Set Excel_Application = CreateObject("Excel.Application")

' Open Excel Workbook
Set Excel_WorkBook =
Excel_Application.Workbooks.Open(DTSGlobalVariable s("FileLocation").Valu
e)

' Get the Worksheet
Set Excel_WorkSheet =
Excel_WorkBook.Worksheets(Cint(DTSGlobalVariables( "SheetNumber").Value))

' Tell Excel where to get the data and add a named range to the
workbook.
' The DTS pump is expecting a source table of "ImportTable" so we name
our range that.
Excel_WorkBook.Names.Add "ImportTable", sActualLocationOfData

' Save the changes back to the workbook. If you fail to do this then
you will get
' a message box asking you if you want to make changes to the Excel
spreadsheet
Excel_WorkBook.Save

' Clean Up Excel Objects
Excel_WorkBook.Close
Set Excel_WorkBook = Nothing
Excel_Application.Quit
Set Excel_Application = Nothing


' Now set the Excel Filename on the Connection
Set oPkg = DTSGlobalVariables.Parent
Set oConn = oPkg.Connections("Excel File")

oConn.DataSource = DTSGlobalVariables("FileLocation").Value

' Clean Up DTS objects
Set oConn = Nothing
Set oPkg = Nothing

Main = DTSTaskExecResult_Success
End Function

The named range is created successfully, and saved to the Excel file.
My problem is that the Transform Data Task is not picking up the named
range, and so does not make it available in the dropdown list for
Table/View on the Source tab. I added some extra code, also from
Allan, as follows:-

Set oPkg = DTSGlobalVariables.Parent
Set cus= oPkg.Tasks("DTSTask_DTSDataPumpTask_1").CustomTask
cus.SourceObjectName = "ImportTable"

however, this through an error on the Transform Data Task, saying that
it couldn't find 'ImportTable'.

Is there something obvious that I'm doing wrong? Like I say, it is
creating the named range ok, it's just that the data pump task is
refusing to acknowledge its presence. My global variables for file
location, data, etc., are also correct, as far as I can see.

Any help would be appreciated

Thanks

Denise


Reply With Quote
  #3  
Old   
dcrawley
 
Posts: n/a

Default Re: Problem using Excel named ranges within a DTS package - 01-03-2007 , 05:42 AM



Hello Allan

Apologies for not getting back sooner. I don't have a pc at home and I
have just come back after the Christmas break.

Yes, that's correct. the Excel connection just doesn't see the named
range. Do you have an idea?

Thanks

Denise



Allan Mitchell wrote:
Quote:
OK so with the Named Range created if you drop on an Excel Connection to
designer. and try to move data from it to somewhere else then the named
range does not appear?



--


Regards



Allan Mitchell


Konesans Ltd
T +44 7966 476 572
F +44 2071 008 479
http://www.konesans.com


"dcrawley" <denise.crawley (AT) hymans (DOT) co.uk> wrote in message
news:1166701273.056563.6410 (AT) f1g2000cwa (DOT) googlegroups.com:

Hello

I am importing data from an Excel spreadsheet into a table, via DTS. I
am trying to use a named range in the spreadsheet, and have used a
script from Allan Mitchell to achieve this:-

' 243 (Excel Named Range)
Option Explicit

Function Main()

Dim sActualLocationOfData
Dim Excel_Application
Dim Excel_WorkBook
Dim Excel_WorkSheet
Dim oPkg
Dim oConn
Dim cus

' Location, which sheet and in which cells is our Data.
' This will produce a string like Sheet1!R14C8:R11C43

sActualLocationOfData = "=Sheet" &
CStr(DTSGlobalVariables("SheetNumber").Value) & _
"!" & DTSGlobalVariables("DataLocation").Value

' Create and set up the Excel File to Import
Set Excel_Application = CreateObject("Excel.Application")

' Open Excel Workbook
Set Excel_WorkBook =
Excel_Application.Workbooks.Open(DTSGlobalVariable s("FileLocation").Valu
e)

' Get the Worksheet
Set Excel_WorkSheet =
Excel_WorkBook.Worksheets(Cint(DTSGlobalVariables( "SheetNumber").Value))

' Tell Excel where to get the data and add a named range to the
workbook.
' The DTS pump is expecting a source table of "ImportTable" so we name
our range that.
Excel_WorkBook.Names.Add "ImportTable", sActualLocationOfData

' Save the changes back to the workbook. If you fail to do this then
you will get
' a message box asking you if you want to make changes to the Excel
spreadsheet
Excel_WorkBook.Save

' Clean Up Excel Objects
Excel_WorkBook.Close
Set Excel_WorkBook = Nothing
Excel_Application.Quit
Set Excel_Application = Nothing


' Now set the Excel Filename on the Connection
Set oPkg = DTSGlobalVariables.Parent
Set oConn = oPkg.Connections("Excel File")

oConn.DataSource = DTSGlobalVariables("FileLocation").Value

' Clean Up DTS objects
Set oConn = Nothing
Set oPkg = Nothing

Main = DTSTaskExecResult_Success
End Function

The named range is created successfully, and saved to the Excel file.
My problem is that the Transform Data Task is not picking up the named
range, and so does not make it available in the dropdown list for
Table/View on the Source tab. I added some extra code, also from
Allan, as follows:-

Set oPkg = DTSGlobalVariables.Parent
Set cus= oPkg.Tasks("DTSTask_DTSDataPumpTask_1").CustomTask
cus.SourceObjectName = "ImportTable"

however, this through an error on the Transform Data Task, saying that
it couldn't find 'ImportTable'.

Is there something obvious that I'm doing wrong? Like I say, it is
creating the named range ok, it's just that the data pump task is
refusing to acknowledge its presence. My global variables for file
location, data, etc., are also correct, as far as I can see.

Any help would be appreciated

Thanks

Denise


Reply With Quote
  #4  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Problem using Excel named ranges within a DTS package - 01-03-2007 , 03:14 PM



A named range should be seen as a table. What if you use that Excel
file in a brand new package?

--


Allan Mitchell
http://wiki.sqlis.com | http://www.sqlis.com | http://www.sqldts.com |
http://www.konesans.com




"dcrawley" <denise.crawley (AT) hymans (DOT) co.uk> wrote


Quote:
Hello Allan

Apologies for not getting back sooner. I don't have a pc at home and I
have just come back after the Christmas break.

Yes, that's correct. the Excel connection just doesn't see the named
range. Do you have an idea?

Thanks

Denise



Allan Mitchell wrote:
OK so with the Named Range created if you drop on an Excel Connection to
designer. and try to move data from it to somewhere else then the named
range does not appear?



--


Regards



Allan Mitchell


Konesans Ltd
T +44 7966 476 572
F +44 2071 008 479
http://www.konesans.com


"dcrawley" <denise.crawley (AT) hymans (DOT) co.uk> wrote in message
news:1166701273.056563.6410 (AT) f1g2000cwa (DOT) googlegroups.com:

Hello

I am importing data from an Excel spreadsheet into a table, via DTS. I
am trying to use a named range in the spreadsheet, and have used a
script from Allan Mitchell to achieve this:-

' 243 (Excel Named Range)
Option Explicit

Function Main()

Dim sActualLocationOfData
Dim Excel_Application
Dim Excel_WorkBook
Dim Excel_WorkSheet
Dim oPkg
Dim oConn
Dim cus

' Location, which sheet and in which cells is our Data.
' This will produce a string like Sheet1!R14C8:R11C43

sActualLocationOfData = "=Sheet" &
CStr(DTSGlobalVariables("SheetNumber").Value) & _
"!" & DTSGlobalVariables("DataLocation").Value

' Create and set up the Excel File to Import
Set Excel_Application = CreateObject("Excel.Application")

' Open Excel Workbook
Set Excel_WorkBook =
Excel_Application.Workbooks.Open(DTSGlobalVariable s("FileLocation").Valu
e)

' Get the Worksheet
Set Excel_WorkSheet =
Excel_WorkBook.Worksheets(Cint(DTSGlobalVariables( "SheetNumber").Value))

' Tell Excel where to get the data and add a named range to the
workbook.
' The DTS pump is expecting a source table of "ImportTable" so we name
our range that.
Excel_WorkBook.Names.Add "ImportTable", sActualLocationOfData

' Save the changes back to the workbook. If you fail to do this then
you will get
' a message box asking you if you want to make changes to the Excel
spreadsheet
Excel_WorkBook.Save

' Clean Up Excel Objects
Excel_WorkBook.Close
Set Excel_WorkBook = Nothing
Excel_Application.Quit
Set Excel_Application = Nothing


' Now set the Excel Filename on the Connection
Set oPkg = DTSGlobalVariables.Parent
Set oConn = oPkg.Connections("Excel File")

oConn.DataSource = DTSGlobalVariables("FileLocation").Value

' Clean Up DTS objects
Set oConn = Nothing
Set oPkg = Nothing

Main = DTSTaskExecResult_Success
End Function

The named range is created successfully, and saved to the Excel file.
My problem is that the Transform Data Task is not picking up the named
range, and so does not make it available in the dropdown list for
Table/View on the Source tab. I added some extra code, also from
Allan, as follows:-

Set oPkg = DTSGlobalVariables.Parent
Set cus= oPkg.Tasks("DTSTask_DTSDataPumpTask_1").CustomTask
cus.SourceObjectName = "ImportTable"

however, this through an error on the Transform Data Task, saying that
it couldn't find 'ImportTable'.

Is there something obvious that I'm doing wrong? Like I say, it is
creating the named range ok, it's just that the data pump task is
refusing to acknowledge its presence. My global variables for file
location, data, etc., are also correct, as far as I can see.

Any help would be appreciated

Thanks

Denise


Reply With Quote
  #5  
Old   
dcrawley
 
Posts: n/a

Default Re: Problem using Excel named ranges within a DTS package - 01-04-2007 , 03:28 AM



If I use the Excel file in a brand new package the named range is not
seen by that one either. I checked the file beforehand, and the named
range is definitely saved within the file, but it just doesn't seem to
be visible within DTS.

There is another named range that was saved into the Excel file before
it was given to me. This named range is available in the dropdown
list, so it's not like the DTS packages aren't picking them up at all.
There just seems to be a problem with the one that's created 'on the
fly'.

Thanks for taking a look at this, Allan. I appreciate it.


Allan Mitchell wrote:

Quote:
A named range should be seen as a table. What if you use that Excel
file in a brand new package?

--


Allan Mitchell
http://wiki.sqlis.com | http://www.sqlis.com | http://www.sqldts.com |
http://www.konesans.com




"dcrawley" <denise.crawley (AT) hymans (DOT) co.uk> wrote in message
news:1167824560.736663.137790 (AT) a3g2000cwd (DOT) googlegroups.com:

Hello Allan

Apologies for not getting back sooner. I don't have a pc at home and I
have just come back after the Christmas break.

Yes, that's correct. the Excel connection just doesn't see the named
range. Do you have an idea?

Thanks

Denise



Allan Mitchell wrote:
OK so with the Named Range created if you drop on an Excel Connection to
designer. and try to move data from it to somewhere else then the named
range does not appear?



--


Regards



Allan Mitchell


Konesans Ltd
T +44 7966 476 572
F +44 2071 008 479
http://www.konesans.com


"dcrawley" <denise.crawley (AT) hymans (DOT) co.uk> wrote in message
news:1166701273.056563.6410 (AT) f1g2000cwa (DOT) googlegroups.com:

Hello

I am importing data from an Excel spreadsheet into a table, via DTS. I
am trying to use a named range in the spreadsheet, and have used a
script from Allan Mitchell to achieve this:-

' 243 (Excel Named Range)
Option Explicit

Function Main()

Dim sActualLocationOfData
Dim Excel_Application
Dim Excel_WorkBook
Dim Excel_WorkSheet
Dim oPkg
Dim oConn
Dim cus

' Location, which sheet and in which cells is our Data.
' This will produce a string like Sheet1!R14C8:R11C43

sActualLocationOfData = "=Sheet" &
CStr(DTSGlobalVariables("SheetNumber").Value) & _
"!" & DTSGlobalVariables("DataLocation").Value

' Create and set up the Excel File to Import
Set Excel_Application = CreateObject("Excel.Application")

' Open Excel Workbook
Set Excel_WorkBook =
Excel_Application.Workbooks.Open(DTSGlobalVariable s("FileLocation").Valu
e)

' Get the Worksheet
Set Excel_WorkSheet =
Excel_WorkBook.Worksheets(Cint(DTSGlobalVariables( "SheetNumber").Value))

' Tell Excel where to get the data and add a named range to the
workbook.
' The DTS pump is expecting a source table of "ImportTable" so we name
our range that.
Excel_WorkBook.Names.Add "ImportTable", sActualLocationOfData

' Save the changes back to the workbook. If you fail to do this then
you will get
' a message box asking you if you want to make changes to the Excel
spreadsheet
Excel_WorkBook.Save

' Clean Up Excel Objects
Excel_WorkBook.Close
Set Excel_WorkBook = Nothing
Excel_Application.Quit
Set Excel_Application = Nothing


' Now set the Excel Filename on the Connection
Set oPkg = DTSGlobalVariables.Parent
Set oConn = oPkg.Connections("Excel File")

oConn.DataSource = DTSGlobalVariables("FileLocation").Value

' Clean Up DTS objects
Set oConn = Nothing
Set oPkg = Nothing

Main = DTSTaskExecResult_Success
End Function

The named range is created successfully, and saved to the Excel file.
My problem is that the Transform Data Task is not picking up the named
range, and so does not make it available in the dropdown list for
Table/View on the Source tab. I added some extra code, also from
Allan, as follows:-

Set oPkg = DTSGlobalVariables.Parent
Set cus= oPkg.Tasks("DTSTask_DTSDataPumpTask_1").CustomTask
cus.SourceObjectName = "ImportTable"

however, this through an error on the Transform Data Task, saying that
it couldn't find 'ImportTable'.

Is there something obvious that I'm doing wrong? Like I say, it is
creating the named range ok, it's just that the data pump task is
refusing to acknowledge its presence. My global variables for file
location, data, etc., are also correct, as far as I can see.

Any help would be appreciated

Thanks

Denise


Reply With Quote
  #6  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Problem using Excel named ranges within a DTS package - 01-04-2007 , 03:57 PM



Can you send me the file?

--


Allan Mitchell
http://wiki.sqlis.com | http://www.sqlis.com | http://www.sqldts.com |
http://www.konesans.com




"dcrawley" <denise.crawley (AT) hymans (DOT) co.uk> wrote


Quote:
If I use the Excel file in a brand new package the named range is not
seen by that one either. I checked the file beforehand, and the named
range is definitely saved within the file, but it just doesn't seem to
be visible within DTS.

There is another named range that was saved into the Excel file before
it was given to me. This named range is available in the dropdown
list, so it's not like the DTS packages aren't picking them up at all.
There just seems to be a problem with the one that's created 'on the
fly'.

Thanks for taking a look at this, Allan. I appreciate it.


Allan Mitchell wrote:

A named range should be seen as a table. What if you use that Excel
file in a brand new package?

--


Allan Mitchell
http://wiki.sqlis.com | http://www.sqlis.com | http://www.sqldts.com |
http://www.konesans.com




"dcrawley" <denise.crawley (AT) hymans (DOT) co.uk> wrote in message
news:1167824560.736663.137790 (AT) a3g2000cwd (DOT) googlegroups.com:

Hello Allan

Apologies for not getting back sooner. I don't have a pc at home and I
have just come back after the Christmas break.

Yes, that's correct. the Excel connection just doesn't see the named
range. Do you have an idea?

Thanks

Denise



Allan Mitchell wrote:
OK so with the Named Range created if you drop on an Excel Connection to
designer. and try to move data from it to somewhere else then the named
range does not appear?



--


Regards



Allan Mitchell


Konesans Ltd
T +44 7966 476 572
F +44 2071 008 479
http://www.konesans.com


"dcrawley" <denise.crawley (AT) hymans (DOT) co.uk> wrote in message
news:1166701273.056563.6410 (AT) f1g2000cwa (DOT) googlegroups.com:

Hello

I am importing data from an Excel spreadsheet into a table, via DTS. I
am trying to use a named range in the spreadsheet, and have used a
script from Allan Mitchell to achieve this:-

' 243 (Excel Named Range)
Option Explicit

Function Main()

Dim sActualLocationOfData
Dim Excel_Application
Dim Excel_WorkBook
Dim Excel_WorkSheet
Dim oPkg
Dim oConn
Dim cus

' Location, which sheet and in which cells is our Data.
' This will produce a string like Sheet1!R14C8:R11C43

sActualLocationOfData = "=Sheet" &
CStr(DTSGlobalVariables("SheetNumber").Value) & _
"!" & DTSGlobalVariables("DataLocation").Value

' Create and set up the Excel File to Import
Set Excel_Application = CreateObject("Excel.Application")

' Open Excel Workbook
Set Excel_WorkBook =
Excel_Application.Workbooks.Open(DTSGlobalVariable s("FileLocation").Valu
e)

' Get the Worksheet
Set Excel_WorkSheet =
Excel_WorkBook.Worksheets(Cint(DTSGlobalVariables( "SheetNumber").Value))

' Tell Excel where to get the data and add a named range to the
workbook.
' The DTS pump is expecting a source table of "ImportTable" so we name
our range that.
Excel_WorkBook.Names.Add "ImportTable", sActualLocationOfData

' Save the changes back to the workbook. If you fail to do this then
you will get
' a message box asking you if you want to make changes to the Excel
spreadsheet
Excel_WorkBook.Save

' Clean Up Excel Objects
Excel_WorkBook.Close
Set Excel_WorkBook = Nothing
Excel_Application.Quit
Set Excel_Application = Nothing


' Now set the Excel Filename on the Connection
Set oPkg = DTSGlobalVariables.Parent
Set oConn = oPkg.Connections("Excel File")

oConn.DataSource = DTSGlobalVariables("FileLocation").Value

' Clean Up DTS objects
Set oConn = Nothing
Set oPkg = Nothing

Main = DTSTaskExecResult_Success
End Function

The named range is created successfully, and saved to the Excel file.
My problem is that the Transform Data Task is not picking up the named
range, and so does not make it available in the dropdown list for
Table/View on the Source tab. I added some extra code, also from
Allan, as follows:-

Set oPkg = DTSGlobalVariables.Parent
Set cus= oPkg.Tasks("DTSTask_DTSDataPumpTask_1").CustomTask
cus.SourceObjectName = "ImportTable"

however, this through an error on the Transform Data Task, saying that
it couldn't find 'ImportTable'.

Is there something obvious that I'm doing wrong? Like I say, it is
creating the named range ok, it's just that the data pump task is
refusing to acknowledge its presence. My global variables for file
location, data, etc., are also correct, as far as I can see.

Any help would be appreciated

Thanks

Denise


Reply With Quote
  #7  
Old   
dcrawley
 
Posts: n/a

Default Re: Problem using Excel named ranges within a DTS package - 01-05-2007 , 09:46 AM



I'm afraid not, as it's a company file. Is there any other information
I can give you without sending the file?

Sorry, I know this makes it more difficult.

Allan Mitchell wrote:

Quote:
Can you send me the file?

--


Allan Mitchell
http://wiki.sqlis.com | http://www.sqlis.com | http://www.sqldts.com |
http://www.konesans.com




"dcrawley" <denise.crawley (AT) hymans (DOT) co.uk> wrote in message
news:1167902902.243513.70360 (AT) q40g2000cwq (DOT) googlegroups.com:

If I use the Excel file in a brand new package the named range is not
seen by that one either. I checked the file beforehand, and the named
range is definitely saved within the file, but it just doesn't seem to
be visible within DTS.

There is another named range that was saved into the Excel file before
it was given to me. This named range is available in the dropdown
list, so it's not like the DTS packages aren't picking them up at all.
There just seems to be a problem with the one that's created 'on the
fly'.

Thanks for taking a look at this, Allan. I appreciate it.


Allan Mitchell wrote:

A named range should be seen as a table. What if you use that Excel
file in a brand new package?

--


Allan Mitchell
http://wiki.sqlis.com | http://www.sqlis.com | http://www.sqldts.com |
http://www.konesans.com




"dcrawley" <denise.crawley (AT) hymans (DOT) co.uk> wrote in message
news:1167824560.736663.137790 (AT) a3g2000cwd (DOT) googlegroups.com:

Hello Allan

Apologies for not getting back sooner. I don't have a pc at home and I
have just come back after the Christmas break.

Yes, that's correct. the Excel connection just doesn't see the named
range. Do you have an idea?

Thanks

Denise



Allan Mitchell wrote:
OK so with the Named Range created if you drop on an Excel Connection to
designer. and try to move data from it to somewhere else then the named
range does not appear?



--


Regards



Allan Mitchell


Konesans Ltd
T +44 7966 476 572
F +44 2071 008 479
http://www.konesans.com


"dcrawley" <denise.crawley (AT) hymans (DOT) co.uk> wrote in message
news:1166701273.056563.6410 (AT) f1g2000cwa (DOT) googlegroups.com:

Hello

I am importing data from an Excel spreadsheet into a table, via DTS. I
am trying to use a named range in the spreadsheet, and have used a
script from Allan Mitchell to achieve this:-

' 243 (Excel Named Range)
Option Explicit

Function Main()

Dim sActualLocationOfData
Dim Excel_Application
Dim Excel_WorkBook
Dim Excel_WorkSheet
Dim oPkg
Dim oConn
Dim cus

' Location, which sheet and in which cells is our Data.
' This will produce a string like Sheet1!R14C8:R11C43

sActualLocationOfData = "=Sheet" &
CStr(DTSGlobalVariables("SheetNumber").Value) & _
"!" & DTSGlobalVariables("DataLocation").Value

' Create and set up the Excel File to Import
Set Excel_Application = CreateObject("Excel.Application")

' Open Excel Workbook
Set Excel_WorkBook =
Excel_Application.Workbooks.Open(DTSGlobalVariable s("FileLocation").Valu
e)

' Get the Worksheet
Set Excel_WorkSheet =
Excel_WorkBook.Worksheets(Cint(DTSGlobalVariables( "SheetNumber").Value))

' Tell Excel where to get the data and add a named range to the
workbook.
' The DTS pump is expecting a source table of "ImportTable" so we name
our range that.
Excel_WorkBook.Names.Add "ImportTable", sActualLocationOfData

' Save the changes back to the workbook. If you fail to do this then
you will get
' a message box asking you if you want to make changes to the Excel
spreadsheet
Excel_WorkBook.Save

' Clean Up Excel Objects
Excel_WorkBook.Close
Set Excel_WorkBook = Nothing
Excel_Application.Quit
Set Excel_Application = Nothing


' Now set the Excel Filename on the Connection
Set oPkg = DTSGlobalVariables.Parent
Set oConn = oPkg.Connections("Excel File")

oConn.DataSource = DTSGlobalVariables("FileLocation").Value

' Clean Up DTS objects
Set oConn = Nothing
Set oPkg = Nothing

Main = DTSTaskExecResult_Success
End Function

The named range is created successfully, and saved to the Excel file.
My problem is that the Transform Data Task is not picking up the named
range, and so does not make it available in the dropdown list for
Table/View on the Source tab. I added some extra code, also from
Allan, as follows:-

Set oPkg = DTSGlobalVariables.Parent
Set cus= oPkg.Tasks("DTSTask_DTSDataPumpTask_1").CustomTask
cus.SourceObjectName = "ImportTable"

however, this through an error on the Transform Data Task, saying that
it couldn't find 'ImportTable'.

Is there something obvious that I'm doing wrong? Like I say, it is
creating the named range ok, it's just that the data pump task is
refusing to acknowledge its presence. My global variables for file
location, data, etc., are also correct, as far as I can see.

Any help would be appreciated

Thanks

Denise


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.