以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  VBA的语句如何改成狐表的?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=70571)

--  作者:wh420
--  发布时间:2015/6/24 16:06:00
--  VBA的语句如何改成狐表的?

以下几句代码如何改成狐表的?

Dim excelApp As New MSExcel.Application
Dim excelRange As MSExcel.Range
Dim Wb As MSExcel.WorkBook=excelApp.WorkBooks.open("C:\\test\\1.xls")

 

Dim c As Range, a As Integer
For Each c In ActiveSheet.UsedRange
If c.MergeCells Then
a = UBound(Split(c.Value, Chr(10)))
If a >= 0 Then Rows(c.Row).RowHeight = 14.25 * (a + 1)
End If
Next


--  作者:大红袍
--  发布时间:2015/6/24 16:17:00
--  

 直接说你想做什么

 

Dim App As New MSExcel.Application
try
    Dim Wb As MSExcel.WorkBook = app.WorkBooks.open("d:\\test.xls")
    Dim rg As MSExcel.Range
    Dim Ws = wb.WorkSheets(1)
    For Each rg In ws.UsedRange
        If rg.MergeCells Then
            Dim i As Integer = UBound(Split(rg.Value, Chr(10)))
            If i >= 0 Then
                ws.Rows(rg.Row).RowHeight = 14.25 * (i + 1)
            End If
        End If
    Next
    app.visible = True
catch ex As exception
    msgbox(ex.message)
    app.quit
End try

 


--  作者:wh420
--  发布时间:2015/6/24 16:24:00
--  

想实现的功能是自动调整“合并单元格“的行高。以上代码没有效果,不知是哪有问题,老师帮忙看看


--  作者:wh420
--  发布时间:2015/6/24 16:43:00
--  
行的高度未发生变化
--  作者:wh420
--  发布时间:2015/6/24 16:50:00
--  

红袍老师?帮忙看看

 


--  作者:大红袍
--  发布时间:2015/6/24 16:51:00
--  
 不要合并单元格啊,合并单元格自动行高很麻烦啊
--  作者:wh420
--  发布时间:2015/6/24 17:11:00
--  

是的知道合并单单格麻烦,所以才用代码解决,这段代码已经在EXCEL的VBA中调试通过,不知道为舍放到狐表里没效果,不知道是不是UBound函数没发挥作用?


--  作者:大红袍
--  发布时间:2015/6/24 17:11:00
--  

 在网上抄来一段,mark 合并单元格自动行高

 

Dim App As New MSExcel.Application
try
    Dim Wb As MSExcel.WorkBook = app.WorkBooks.open("d:\\test.xls")
    Dim rg As MSExcel.Range
    Dim Ws = wb.WorkSheets(1)
    Dim tempWs = wb.WorkSheets.Add
    For Each rg In ws.UsedRange
        If rg.MergeCells Then
            Dim tempCell As MSExcel.Range
            Dim width As Double = 0
            Dim tempCol
            For Each tempcol In rg.MergeArea.Columns
                width = width + tempcol.ColumnWidth
            Next
            tempWs.Columns(1).WrapText = True
            tempWs.Columns(1).ColumnWidth = width
            tempWs.Columns(1).Font.Size = rg.Font.Size
            tempWs.Cells(1, 1).Value = rg.Value
            tempWs.Cells(1, 1).RowHeight = 0
            tempWs.Cells(1, 1).EntireRow.Activate
            tempWs.Cells(1, 1).EntireRow.AutoFit
            If (rg.RowHeight < tempWs.Cells(1, 1).RowHeight) Then
                Dim tempHeight As Double
                Dim tempCount As Integer
                tempHeight = tempWs.Cells(1, 1).RowHeight
                tempCount = rg.MergeArea.Rows.Count
                For Each addHeightRow As object In rg.MergeArea.Rows
                   
                    If (addHeightRow.RowHeight < tempHeight / tempCount) Then
                        addHeightRow.RowHeight = tempHeight / tempCount
                    End If
                    tempHeight = tempHeight - addHeightRow.RowHeight
                    tempCount = tempCount - 1
                Next
                rg.WrapText = True
            End If
        End If
    Next
    app.DisplayAlerts = False
    tempWs.Delete
    app.visible = True
catch ex As exception
    msgbox(ex.message)
    app.quit
End try

 


--  作者:wh420
--  发布时间:2015/6/24 17:11:00
--  
Sub aaa()
    Dim c As Range, a As Integer
    For Each c In ActiveSheet.UsedRange
        If c.MergeCells Then
            a = UBound(Split(c.Value, Chr(10)))
            If a >= 0 Then Rows(c.Row).RowHeight = 14.25 * (a + 1)
        End If
    Next
End Sub

--  作者:大红袍
--  发布时间:2015/6/24 17:13:00
--  
 看8楼。