Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find the name of a worksheet using activeX inside DTS

Status
Not open for further replies.

GJP55

Technical User
Feb 2, 2003
220
GB

Does anybody know the correct code to identify a worksheet name from an Excel file ?. I am writing code to look at each worksheet in an excel file and will loop it through each one during an import.

Code I have so far but this does not work with the worksheet section.

Thanks



Function Main

Set MsExcObj = CreateObject("Excel.Application")
Set wbk = GetObject("J:\Precedent Decisions by country.xls")
Set Wsht = wbk.Worksheets

For Each Wsht In wbk
msgbox wbk.name
Next

Set wbk = Nothing
Set MsExcObj = Nothing
Set Wsht = Nothing

Main = DTSTaskExecResult_Success
End Function
 
I don't know much about DTS, but I have some VB code that will enumerate a list of excel worksheets from a workbook. This approach may work for you, and if not, perhaps it's a least a starting point.

Code:
Dim DB As ADODB.Connection
Dim RS As ADODB.Recordset

Set DB = CreateObject("ADODB.Connection")
DB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=[!]C:\tektips.xls[/!];Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
Call DB.Open

Set RS = DB.OpenSchema(adSchemaTables)

While Not RS.EOF
    Debug.Print RS.Fields.Item("Table_Name").Value
    RS.MoveNext
Wend
Call RS.Close
Set RS = Nothing

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Hi,

Thanks for your reply. Definately in the right direction there.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top