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!

Excel worksheet into global variable for dynamic connection

Status
Not open for further replies.

DanC

Programmer
Jan 12, 2001
65
US
I'm trying to get the worksheet name from an excel workbook to pass into a global variable to be used to dynamically change the import task for importing the sheet. I can get the filename and path using the File System Object, but I can't seem to be able to get the first worksheet's name. Here's the code (probably not the best way)

Function Main()
Dim fsoObject, objFolder, objFile, colFiles, strFileName

Set fsoObject = CreateObject("Scripting.FileSystemObject")
Set objFolder = fsoObject.GetFolder("c:\projects\client\source\")
Set colFiles = objFolder.Files


If colFiles.Count > 0 Then
For Each objFile in colFiles
If left(objFile.Name,4) = "prod" Then
strFileName = objFile.Name
End If
Next
End If

DTSGlobalVariables("FileName").value = strFileName
DTSGlobalVariables("FilePath").value = objFolder & "\" & strFileName
DTSGlobalVariables("SheetName").value =

Main = DTSTaskExecResult_Success

Set fsoObject = nothing
Set objFolder = nothing
Set objFile = nothing
Set colFiles = nothing

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top