token_remedie
Registered User.
- Local time
- Today, 22:46
- Joined
- Jul 7, 2011
- Messages
- 78
so I'm trying to use filedialog to open a file then pass that filename to dim myxlworkbook as excel.application so that it populates a combo box of the sheetnames which ill then take that selection of sheetnames for docmd.transferspreadsheet import.
anyway I'm getting runtime error 91 Object Variable or With block variable not set.
maybe i've been staring at it too long but I thought I did that?
I should mention I'm still learning.
anyway I'm getting runtime error 91 Object Variable or With block variable not set.
maybe i've been staring at it too long but I thought I did that?
I should mention I'm still learning.
Code:
Dim fd As FileDialog
Dim strfile As String
Dim strsearchpath As String
Dim vrtSelectedItem As Variant
Dim strSql As String
Dim MyXLApp As Excel.Application
Dim MyXLWorkBook As Excel.Workbook
Set myDialog = Application.FileDialog(msoFileDialogOpen)
'searchpath is set at c:\ for now, needs to be changed when live
strsearchpath = "c:\"
With myDialog
.AllowMultiSelect = False
.Filters.Add "Excel Files", "*.xlsx", 1
.Title = "locate files"
.InitialFileName = strsearchpath
DoCmd.SetWarnings False
If .Show = True Then
For Each vrtSelectedItem In .SelectedItems
MsgBox "file chosen = " & vrtSelectedItem
Set MyXLApp = New Excel.Application
Set MyXlWorkBookk = MyXLApp.Workbooks.Open(vrtSelectedItem)
Next
For i = 1 To MyXLWorkBook.Sheets.Count
Set myXLSheet = MyXLWorkBook.Sheets(i)
myXLSheet.Select
Combo4.AddItem myXLSheet.Name
Next i