Results 1 to 3 of 3

Thread: Word table to Excel

  1. #1
    Neophyte nigel1's Avatar
    Join Date
    Sep 2019
    Posts
    1
    Articles
    0
    Excel Version
    2016

    Word table to Excel



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hello,

    I'm trying to get VBA in Excel open a Word Doc and after finding a specific word to go to the 1st table below that word and copy specific cells from it back to Excel.


    Code:
    Sub Test()
    Dim ws As Worksheet
    Dim objWord AsObject
    Dim i AsInteger
    Dim strValue AsString
    Set objWord = CreateObject("Word.Application")
    
    objWord.Visible =True
    objWord.Documents.Open "C:\Users\Nigel\Desktop\Test2.docx"
    
    objWord.Activate
    
    With objWord.Selection.Find
    .Text ="Test"
    If objWord.Selection.Find.Text >0Then
    MsgBox "Found"
    
    TableStart = Selection.Tables(1).Range.Start
    Selection.GoTo wdGoToTable, wdGoToNext,1
    If Selection.Tables(1).Range.Start = TableStart ThenExitSub
    
    Selection.GoToNext wdGoToTable = a
    Dim x AsLong, y AsLong
    x =8: y =1
    With.Tables(a)
    For rowNb =1To1
    For colNb =2To2
    Cells(x, y)= WorksheetFunction.Clean(.Cell(rowNb, colNb).Range.Text)
    y = y +1
    Next colNb
    y =1
    x = x +1
    Next rowNb
    EndWith
    x = x +2
    Else
    MsgBox "Didn't"
    
    EndIf
    EndWith
    
    EndSub

  2. #2

  3. #3
    Acolyte macropod's Avatar
    Join Date
    Mar 2017
    Posts
    45
    Articles
    0
    Excel Version
    2010
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •