I have an Excel workbook with multiple worksheets.
The third worksheet:
1) Is titled "Priority Codes"
2) Contains data in columns "A" & "B" - number of rows is unknown
3) Some of the cells are in "BOLD" type
I want to import the data in column "A" if it is in "BOLD" into an access table called "tblPriorityPriorityCodes". I have the VBA code to import all of the data in column "A" if it is the only worksheet in the workbook but I don't know how to address the cells in a multi-worksheet workbook, nor do I know how to test if the cell's "BOLD" attribute is true.
I've searched the forums and FAQ's but didnt' see this topic discussed. Any help will be greatly appreciated!
Here's my code:
Private Sub cmdReadProjectCodes_Click()
Dim a, w, WSN As Object
Dim filename, strContinue As String
Dim db As DAO.Database
Dim rs1 As DAO.Recordset
Dim intRow As Integer
filename = "d:\Project Code Priorities.xls"
Set a = CreateObject("Excel.Application"
Set w = a.Workbooks.Add(filename)
Set WSN = w.Worksheets(1)
WSN.Activate
Set db = CurrentDb
Set rs1 = db.OpenRecordset("tblPriorityProjectCodes", dbOpenDynaset)
'Delete existing records in tblPriorityProjectCodes
DoCmd.OpenQuery ("qdelPriorityProjectCodes"
' data in spreadsheet starts on line 2 (line 1 is fieldname)
strContinue = "Y"
intRow = 2
Do While strContinue = "Y"
If Len(Trim(w.activesheet.cells(intRow, 1))) > 0 Then
rs1.AddNew
rs1![project code] = w.activesheet.cells(intRow, 1)
rs1.Update
intRow = intRow + 1
Else
strContinue = "N"
Exit Do
End If
Loop
rs1.Close
w.Close
Set rs1 = Nothing
Set a = Nothing
Set w = Nothing
Set WSN = Nothing
End Sub
The third worksheet:
1) Is titled "Priority Codes"
2) Contains data in columns "A" & "B" - number of rows is unknown
3) Some of the cells are in "BOLD" type
I want to import the data in column "A" if it is in "BOLD" into an access table called "tblPriorityPriorityCodes". I have the VBA code to import all of the data in column "A" if it is the only worksheet in the workbook but I don't know how to address the cells in a multi-worksheet workbook, nor do I know how to test if the cell's "BOLD" attribute is true.
I've searched the forums and FAQ's but didnt' see this topic discussed. Any help will be greatly appreciated!
Here's my code:
Private Sub cmdReadProjectCodes_Click()
Dim a, w, WSN As Object
Dim filename, strContinue As String
Dim db As DAO.Database
Dim rs1 As DAO.Recordset
Dim intRow As Integer
filename = "d:\Project Code Priorities.xls"
Set a = CreateObject("Excel.Application"
Set w = a.Workbooks.Add(filename)
Set WSN = w.Worksheets(1)
WSN.Activate
Set db = CurrentDb
Set rs1 = db.OpenRecordset("tblPriorityProjectCodes", dbOpenDynaset)
'Delete existing records in tblPriorityProjectCodes
DoCmd.OpenQuery ("qdelPriorityProjectCodes"
' data in spreadsheet starts on line 2 (line 1 is fieldname)
strContinue = "Y"
intRow = 2
Do While strContinue = "Y"
If Len(Trim(w.activesheet.cells(intRow, 1))) > 0 Then
rs1.AddNew
rs1![project code] = w.activesheet.cells(intRow, 1)
rs1.Update
intRow = intRow + 1
Else
strContinue = "N"
Exit Do
End If
Loop
rs1.Close
w.Close
Set rs1 = Nothing
Set a = Nothing
Set w = Nothing
Set WSN = Nothing
End Sub