选择多个MS Word页并复制选择

时间:2018-08-23 20:17:54

标签: word-vba

我想选择多个MS单词页面,然后复制所有内容并将其粘贴到Excel中。 到目前为止,这是我的代码:

   Sub importData()
   Dim wrdDoc As String, i As Long, wordapp As Object

   Set wordapp = CreateObject("word.Application")
   wordapp.Documents.Open "Doc Address"
   wordapp.Visible = True

非常感谢所有帮助!

2 个答案:

答案 0 :(得分:0)

尝试:

Sub Demo()
Application.ScreenUpdating = False
Dim wdApp As New Word.Application, wdDoc As Word.Document
Const myFile As String = "file path & name"
With wdApp
  Set wdDoc = .Documents.Open(Filename:=myFile, AddToRecentFiles:=False, Visible:=False)
  With wdDoc
    .Range.Copy
    ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteAll
    .Close False
  End With
  .Quit False
End With
Set wdDoc = Nothing: Set wdApp = Nothing
Application.ScreenUpdating = True
End Sub

答案 1 :(得分:0)

sub wordappstuff()

'   declare word app
Dim msword As Word.Application, myWordDoc As Word.Document
Dim i As Integer, sheetName As String, Timer As Double
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Timer = Now()
Set msword = New Word.Application

For i = 1 To 7
    myFile = "FILENAMEx"
    sheetName = Range("SheetName").Offset(i, 0).Value
    Sheets.Add.Name = sheetName
    Set myWordDoc = msword.Documents.Open(myFile)
  myWordDoc.Content.Copy
Sheets(sheetName).Range("A1").PasteSpecial xlPasteValues
myWordDoc.Close False
Next i
msword.Quit False
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
MsgBox (Format(Now() - Timer, "HH:MM:SS"))
End Sub