返回列表 上一主題 發帖

word的vba, 要怎麼改轉到excel後的字型及格式

和在Excel里是一样的:
Sub test()
    Dim xlWkApp As Object, xlWk As Object
    Set xlWkApp = CreateObject("excel.application")
    With xlWkApp
        .Visible = True
        With .Workbooks.Add.Sheets(1)
            With .Range("a1")
                .Value = ThisDocument.Tables(2).Cell(2, 6)
                .Font.ColorIndex = 3
                .HorizontalAlignment = 3
            End With
            .Range("a2") = ThisDocument.Tables(2).Cell(5, 6)
            .Range("a1:a2").Borders.LineStyle = 1
        End With
    End With
End Sub

TOP

我的版本是Office2003,word表格里的内容输入到excel后,包含了一些非打印字符.我上次删的那个贴子对此进行了处理.
Function myCell(s)
    Dim tmp
    tmp = Replace(s, Chr(13), "")
    tmp = Replace(tmp, Chr(7), "")
    tmp = Replace(tmp, Chr(32), "")
    myCell = tmp
End Function
Sub test()
    Dim xlWkApp As Object, xlWk As Object
    Set xlWkApp = CreateObject("excel.application")
    With xlWkApp
        .Visible = True
        With .Workbooks.Add.Sheets(1)
            With .Range("a1")
                .Value = myCell(ThisDocument.Tables(2).Cell(2, 6))
                .Font.ColorIndex = 3
                .HorizontalAlignment = 3
            End With
            .Range("a2") = myCell(ThisDocument.Tables(2).Cell(5, 6))
            .Range("a1:a2").Borders.LineStyle = 1
        End With
    End With
End Sub

TOP

        靜思自在 : 不怕事多,只怕多事。
返回列表 上一主題