|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Detect merged cells in excel spreadsheet
Hi
I've made a small program that opens an excel spreadsheet and converts the data into html table. The only problem is that I can't seem to detect if cells are merged. How is that possible? I’ve included the code that converts the spreadsheet to html: Private Sub Command1_Click() Dim aObjExcel As New Excel.Application Dim aObjWorkSheet As Excel.Worksheet Dim aLngColCount As Long Dim aLngRowCount As Long Dim aLngCol As Long Dim aLngRow As Long Dim aStrHtml As String aObjExcel.Workbooks.Open "c:\spreadsheet.xls" With aObjExcel.ActiveWorkbook For Each aObjWorkSheet In .Worksheets aIntColCount = aObjWorkSheet.UsedRange.Columns.Count aIntRowCount = aObjWorkSheet.UsedRange.Rows.Count aStrHtml = aStrHtml & "<table border=1>" & _ "<tr>" & _ "<td colspan=" & aIntColCount & ">" & aObjWorkSheet.Name & "</td>" & _ "</tr>" For aLngRow = 1 To aIntRowCount aStrHtml = aStrHtml & "<tr>" For aLngCol = 1 To aIntColCount If aObjCol.aObjWorkSheet.Cells(aLngRow, aLngCol).MergeCells = True Then End If aStrHtml = aStrHtml & "<td>" & aObjCol.aObjWorkSheet.Cells(aLngRow, aLngCol).Value & " </td>" Next aLngCol aStrHtml = aStrHtml & "</tr>" Next aLngRow aStrHtml = aStrHtml & "</table>" Next aObjWorkSheet End With aObjExcel.Quit Set aObjExcel = Nothing MsgBox aStrHtml End Sub |
|
#2
|
|||
|
|||
|
Hi,
Haven't looked into your code yet but what you would do is unmerge every cell in your sheet with the code below : Code:
ActiveSheet.Range("A1:E10").Select
Selection.UnMerge
In that way no merged cells will remain in the range you choose Hope this helps you out Kind regards Marc |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Detect merged cells in excel spreadsheet |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|