Hi,
I have this code
The yellow blocked code was the error source, saying "Object does not support this property or method". I have added Microsoft Excel 12.0 Object Library references in Tools>References.
What I want to achieve in the "for TblAssyPart" block, is to get the cell B value in the Excel file where cell A value is not empty (thus <> "" at the Do Until setCell). I guess my code is not proper (have not done VBA for excel file for a long time). Can anyone give me hint to solve my problem? Thanks
I have this code
Code:
Private Function insertBOM(strInputFileName As String)
Dim itemNo As Long
Dim partNumber As String
Dim description As String
Dim qty As Long
Dim allBlank As Long
Dim excelLine As Long
Dim insTblAssyQry As String
Dim insTblPartQry As String
Dim insTblSubAssyQry As String
Dim excelApp As Excel.Application
Dim workbook As Excel.workbook
Dim worksheet As Excel.worksheet
Dim dbs As Database
Set excelApp = CreateObject("Excel.application")
Set workbook = GetObject(strInputFileName)
Set worksheet = workbook.Worksheets("Sheet1")
Set dbs = CurrentDb
allBlank = 0
excelLine = 1
Do While allBlank < 5
partNumber = worksheet.Cells(excelLine, "B")
If partNumber = "" Then
allBlank = allBlank + 1
excelLine = excelLine + 1
Else
allBlank = 0
If worksheet.Cells(excelLine, "B").interior.colorindex = 3 And worksheet.Cells(excelLine, "A") <> "" Then 'if RED with UnitNO
itemNo = worksheet.Cells(excelLine, "A")
description = worksheet.Cells(excelLine, "C")
insTblAssyQry = "INSERT INTO TblASSYTEST([Number],[AssyDesc]) " _
& "VALUES('" & partNumber & "','" & description & "')"
MsgBox (insTblAssyQry)
DoCmd.SetWarnings False
DoCmd.RunSQL insTblAssyQry
DoCmd.SetWarnings True
ElseIf worksheet.Cells(excelLine, "B").interior.colorindex = 3 And worksheet.Cells(excelLine, "A") = "" Then 'if RED without UnitNo
description = worksheet.Cells(excelLine, "C")
insTblPartQry = "INSERT INTO TblPARTTEST([PartNumber],[PartDesc]) " _
& "VALUES('" & partNumber & "','" & description & "')"
MsgBox (insTblPartQry)
DoCmd.SetWarnings False
DoCmd.RunSQL insTblPartQry
DoCmd.SetWarnings True
'=================for TblAssyPart======================
Dim ctr As Long
Dim setCell As String
ctr = 1
[highlight #FCE94F] worksheet("Sheet1").Cells(excelLine, "A").Select[/highlight]
setCell = ActiveCell
Do Until setCell <> ""
setCell = ActiveCell.Offset(-ctr, 0)
ctr = ctr + 1
Loop
msgbox(Activesheet.cells(excelLine-ctr,"B").value)
'======================================================
..
..
..
The yellow blocked code was the error source, saying "Object does not support this property or method". I have added Microsoft Excel 12.0 Object Library references in Tools>References.
What I want to achieve in the "for TblAssyPart" block, is to get the cell B value in the Excel file where cell A value is not empty (thus <> "" at the Do Until setCell). I guess my code is not proper (have not done VBA for excel file for a long time). Can anyone give me hint to solve my problem? Thanks