Armitage2k
Registered User.
- Local time
- Tomorrow, 06:52
- Joined
- Oct 10, 2009
- Messages
- 34
Hi!
I am trying to import a specific excel spreadsheet which is to be defined in an inputbox prior import. however, when the code should select the prior defined sheet, it returns the error message that this action would not be support. Surprisingly, the code used to work before...
I first thought it might has to do with the references or something, but I could not find any clues from there.
Would appreciate if someone could point me into the right direction.
thanks a lot!
A2k
I am trying to import a specific excel spreadsheet which is to be defined in an inputbox prior import. however, when the code should select the prior defined sheet, it returns the error message that this action would not be support. Surprisingly, the code used to work before...
I first thought it might has to do with the references or something, but I could not find any clues from there.
Code:
Sub GetDataFromClosedWorkbook()
Dim xlApplication As Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlWorksheet As Excel.Worksheet
Dim db As Database, rec As Recordset
Dim Filename As Object
Dim Selection, Category, Finished As String
Set db = CurrentDb
Set Filename = Application.FileDialog(msoFileDialogFilePicker)
With Filename
.InitialView = msoFileDialogViewDetails:
.InitialFileName = "C:\":
.Filters.Clear:
.Filters.Add "Pick .xls File", "*.xls", 1:
.ButtonName = "Import file":
.Title = "Search for Database_Import.xls file"
' If no file is selected, close the sub, else keep going
If .Show = -1 Then
Selection = .SelectedItems(1)
Else:
Exit Sub
End If
End With
Category = InputBox("Which worksheet do you want to import? - VIP - PCP - LSG - OCT - IHG", "Select Entries", "VIP")
Set xlApplication = CreateObject("Excel.Application")
Set xlWorkbook = xlApplication.Workbooks.Open(Selection, True, True)
[B][COLOR="Red"]Set xlWorksheet = xlApplication.Workbook.Worksheets(Category) [/COLOR][/B]' define which worksheet shall be imported
Set rec = db.OpenRecordset(Category)
' open the source workbook, read only
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, Category, Selection, True
' close the source workbook without saving any changes
xlWorkbook.Close False
Finished = MsgBox("Import of " & Category & " successfully finished", vbOKOnly, "Finished")
Set xlWorkbook = Nothing ' free memory
rec.Close
End Sub
Would appreciate if someone could point me into the right direction.
thanks a lot!
A2k