-
1 # 使用者1762952007506
-
2 # 李雯雯
Sub 自動把word表格轉換到Excel()
On Error Resume Next """"""出錯繼續(應對不規範的表格)
""""""重新命名所有WORD檔案為大寫“A”。如 A (1).docx。
""maxcolumn(xex)
Dim maxrowend2
Dim wdApp
For w3 = 1 To 2 想合併多少個文件?
maxrowend2 = Sheets("sheet1").[a65536].End(xlUp).Row
Set wdApp = CreateObject("word.application")
path_ = ThisWorkbook.Path
wdApp.Documents.Open (path_ & "\" & "A (" & w3 & ")" & ".docx")
wdApp.Visible = True
n = wdApp.ActiveDocument.Tables.Count """"有多少個表格
"x = 0
x = maxrowend2 + 1 """"初始行號
y = 0
For i = 1 To n
rs = wdApp.ActiveDocument.Tables(i).Rows.Count """"有多少個行
cs = wdApp.ActiveDocument.Tables(i).Columns.Count """"有多少個列
""""""ghg = MsgBox(rs & "行列" & cs) """""""""""""""""""""""""""""""提示
For m = 1 To rs
x = x + 1
y = 1
ThisWorkbook.Sheets("Sheet1").Cells(x, 1) = "源自A (" & w3 & ")" & ".docx" & "; 第" & i & " 表 " """"""""""9999999999999999999
For n = 1 To cs
vv = wdApp.ActiveDocument.Tables(i).Cell(m, n)
ThisWorkbook.Sheets("Sheet1").Cells(x, y + 1) = Mid(vv, 1, Len(vv) - 1) """空第一列
y = y + 1
Next
Next
Next
wdApp.Application.Quit "關閉word文件
Set wdApp = Nothing "釋放物件變數的記憶體
Next
End Sub
回覆列表
VBA可以批次匯入excel資料至word,也能自動調整格式
建議你找幾個示例自己修改
交給別人做可能會洩露你的資料,並且光溝通詳細的需求可能就要花幾個小時甚至幾天時間