返回列表 上一主題 發帖

[發問] 讀取表格

我指的是程式執行時,
會自動讀取指定路徑的word檔案,
並把檔案寫回Excel上面,
但我希望他的格式不會變 ...
kannas 發表於 2010-12-1 01:05



   一個非常懶的方法
copy and paste....
  1. Sub dsa()
  2.        Dim Wd   'Word
  3.        Dim Dc   '文件
  4.        Dim Tb   '內表
  5.        Dim i, j    '定位
  6.    
  7.            Sheet1.UsedRange.EntireRow.Delete    'Excel Sheet1 清表
  8.            Set Wd = CreateObject("Word.Application")
  9.            Dim RgR As Range
  10.            Set Dc = Wd.Documents.Open("C:\temp\1.DOC ") '檔名
  11.            Wd.Visible = True
  12.            With Wd.Selection.Find
  13.                 .Text = "^l"
  14.                 .Replacement.Text = " "
  15.             End With
  16.             Wd.Selection.Find.Execute Replace:=2
  17.             With Wd.Selection.Find
  18.                 .Text = "^p"
  19.                 .Replacement.Text = " "
  20.             End With
  21.             Wd.Selection.Find.Execute Replace:=2
  22.            For Each Tb In Dc.tables
  23.                Set RgR = Sheet1.UsedRange.EntireRow.Offset(Sheet1.UsedRange.Rows.Count + 1, 0).Cells(1)
  24.                Tb.Range.Copy
  25.                RgR.Select
  26.                ActiveSheet.PasteSpecial Format:="HTML"
  27.            Next
  28.          
  29.            Wd.Quit
  30. End Sub
複製代碼
懂得發問,答案就會在其中

今日の一秒は  明日にない
http://kimbalko-chi.blogspot.com
http://kimbalko.blogspot.com

TOP

        靜思自在 : 虛空有盡.我願無窮,發願容易行願難。
返回列表 上一主題