Sub test()
Dim wrdApp As Word.Application
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Dim wrdDoc As Word.Document
Set wrdDoc = wrdApp.Documents.Add
Dim wrdTbl As Word.Table
Set wrdTbl = wrdDoc.Tables.Add(Range:=wrdDoc.Range, NumRows:=6, NumColumns:=1)
With wrdTbl
.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleSingle
.Borders(wdBorderVertical).LineStyle = wdLineStyleSingle
For r = 1 To 6
.Cell(r, 1).Range.Text = ActiveSheet.Cells(r, 1).Value
Next r
End With
' Dim temp3 As ListGalleries
For r = 1 To 6 Step 2
Set temp3 = wrdApp.ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1)
With temp3
.NumberFormat = "%1."
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = CentimetersToPoints(0.63)
.Alignment = wdListLevelAlignLeft
.TextPosition = CentimetersToPoints(1.27)
.TabPosition = wdUndefined
.StartAt = r
End With
Dim rng As Range
Set rng = wrdDoc.Range(Start:=wrdDoc.Range.Rows(1).Range.Start, End:=wrdDoc.Range.Rows(6).Range.End)
rng.ListFormat.ApplyListTemplate ListTemplate:=temp3
Next r
End Sub
上述代碼適用於Word VBA,但不適用於Excel。 不知道爲什麼如此難以在Excel中使用ListGalleries來控制Word ... 已經在網上找到了數百萬條目,但很難找到。 任何人都可以請幫助一下嗎?我絕望......在Word中VBA 近零在線報道...Excel VBA:如何在Excel中使用ListTemplates來控制Word?
感謝您的回覆。以下是插圖: http://www.youtube.com/watch?v=tVZhav-E92w&feature=youtu.be –