- 帖子
- 4901
- 主題
- 44
- 精華
- 24
- 積分
- 4916
- 點名
- 105
- 作業系統
- Windows 7
- 軟體版本
- Office 20xx
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台北
- 註冊時間
- 2010-4-30
- 最後登錄
- 2025-5-1
               
|
6#
發表於 2010-7-9 00:04
| 只看該作者
本帖最後由 Hsieh 於 2010-7-9 00:08 編輯
回復 5# ianlcc - Private Sub Workbook_BeforeClose(Cancel As Boolean)
- '請先設定引用項目Micrsoft Word 10.0 ObjectLibrary
- Dim Ar()
- Dim Wd As Word.Application, Doc As Document
- Application.ScreenUpdating = False
- Set Wd = CreateObject("Word.Application")
- With Sheet2
- For i = 1 To .[E65536].End(xlUp).Row
- ReDim Preserve Ar(s)
- Ar(s) = Array(.Cells(i, 5).Value, .Cells(i, 4).Value, .Cells(i, 3).Value)
- s = s + 1
- Next
- End With
- With Wd
- Set Doc = .Documents.Open(ThisWorkbook.Path & "\類別.doc") 'doc檔名自行更改
- With Doc.Tables(1) '必須存在表格
- r = s
- Do Until .Rows.Count <= s
- .Rows(r).Delete
- r = r - 1
- Loop
-
- For i = 0 To UBound(Ar)
- If i = .Rows.Count Then .Rows.Add
- For j = 0 To 2
- .Cell(i + 1, j + 1).Range.Text = Ar(i)(j)
- Next
- Next
- End With
- Doc.Save
- .Quit
- End With
- Application.ScreenUpdating = True
- End Sub
複製代碼 |
|