簡體   English   中英

使用Excel VBA將Word內容復制到Excel電子表格中

[英]Copy Word content into Excel spreadsheet using Excel VBA

我有一套Word文檔,其中包含評估表。 我可以手動將它們及其格式復制並粘貼到excel電子表格中,但是我有興趣使用VBA自動執行此操作,因為我有大約400個。

在保留所有格式的同時,如何打開每個文件並將數據復制並粘貼到excel中?

我會從剪貼板中獲得文本:

Dim DataObj As New MSForms.DataObject
DataObj.GetFromClipboard
myString = DataObj.GetText

然后解析該文本。 您可以查看此鏈接https://excelmacromastery.com/vba-string-functions/#Extracting_Part_of_a_String

第一步是在Excel的vb編輯器中設置對Microsoft Word的引用。 然后您可以打開這樣的Word文檔

Dim wd as new Word.application
dim doc as word.document
set doc = wd.documents.open("path and mame of word document")

'使用表就像這樣'假設目標是指向Excel單元格的指針

Dim t As Word.Table
Set t = doc.Tables(1)
t.Cell(3, 2).Range.Copy    'this copies the cell at row 3, column 2
target.PasteSpecial xlPasteValues

那應該讓你開始

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM