請問一下,以下為word的vba, 要怎麼改轉到excel後的字型及格式(格線,置中等....)
Sub test()
Dim xlWkApp As Object, xlWk As Object
Set xlWkApp = CreateObject("excel.application")
With xlWkApp
.Visible = True
Set xlWk = .Workbooks.Add
xlWk.Sheets(1).Range("a1") = ThisDocument.Tables(2).Cell(2, 6)
xlWk.Sheets(1).Range("a2") = ThisDocument.Tables(2).Cell(5, 6)
End With
End Sub作者: et5323 時間: 2010-10-29 12:52
和在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作者: color790 時間: 2010-10-29 15:43
我的版本是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作者: color790 時間: 2010-11-1 20:54
真的可行耶~謝謝et5323 ^^
1.不過兩個程式為什麼有這樣的差別?
2.這一段的用意是?不懂
Function myCell(s)
Dim tmp
tmp = Replace(s, Chr(13), "")
tmp = Replace(tmp, Chr(7), "")
tmp = Replace(tmp, Chr(32), "")
myCell = tmp
End Function