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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Several Excel imports in one database.

Status
Not open for further replies.

Ricky1946

Programmer
Jul 11, 2001
76
GB
Hello,
I need to import several Excel spreadsheets into one database. Is there anyway that I can read the title of the spreadsheet in order to place it in its own category within Access, or perhaps you can think of another way of doing this. Effectively I need to be able to have several 'sub-categories' within one database.Perhaps using VBA?
Any help would be appreciated.
Many thanks in advance.
Ian

"To say 'thankyou' encourages others."
 
I use this code to track the correct worksheet:

Function IsArk(ArkName)
On Error GoTo err_IsArk
Dim MyXL As Object
Dim Svar, Ex_Ark
Set MyXL = GetObject(, "Excel.Application")
If Err.Number <> 0 Then ExcelWasNotRunning = True
Err.Clear
If ExcelWasNotRunning Then
Set MyXL = CreateObject(&quot;Excel.Application&quot;)
Resume Next
End If

Herman
Ex_Ark = MyXL.ActiveWorkbook.ActiveSheet.name
If Right(Ex_Ark, 1) = Svar Then MyXL.ActiveWorkbook.ActiveSheet.name = ArkName
For I = 1 To MyXL.ActiveWorkbook.Sheets.Count
Svar = MyXL.ActiveWorkbook.Sheets(I).name
If InStr(1, Svar, ArkName) Then
MyXL.ActiveWorkbook.Sheets(Svar).Select
IsArk = True
End If
Next I
MyXL.ActiveWorkbook.Save
MyXL.ActiveWorkbook.Close
exit_IsArk:
Set MyXL = Nothing
Exit Function

err_IsArk:
If Err = XL_NOTRUNNING Then
Set MyXL = CreateObject(&quot;Excel.Application&quot;)
MyXL.Workbooks.Add
Resume Next
Else
MsgBox Err.Number & &quot; - &quot; & Err.Description, , &quot;YrAppName&quot;
End If
Resume exit_IsArk
End Function
 
Hello Herman,
Thanks very much for your prompt reply and I will take a note of your code, but it is not the seperate worksheet that I need to see - but I need to be able to import several spreadsheet files into one database and differentiate between them. Can you help here?
Thanks again.
Ian

&quot;To say 'thankyou' encourages others.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top