Consulting

Results 1 to 9 of 9

Thread: Word table

  1. #1
    Banned VBAX Newbie
    Joined
    Sep 2019
    Posts
    4
    Location

    Word table

    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.

    For example, if the specific word to be found in the Word Document is "Apples", the Excel VBA should target the 1st table below that specific word (which can be the 2nd table in the Word Document) and get some cells from it back to Excel. So I'm guessing that something like a complete search in the entire Word Document should be done to look for "Apples", then create a range to count the tables from that point until the end of the document. Once this is done some cells from the first table after the searched word was found should be copied into Excel.

    Below is what I've tried so far, any suggestions would be much appreciated !
    Cheers !

    Sub Test()

    Dim ws As Worksheet
    Dim objWord AsObject
    Dim i AsInteger
    Dim strValue AsString
    Dim wdApp AsNew Word.Application, wdDoc As Word.Document, wdTbl As
    Word
    .Table
    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
    Last edited by nigel1; 09-16-2019 at 01:53 PM.

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,891
    Location
    Cross-posted at: https://stackoverflow.com/questions/...ble-into-excel
    Please read VBA Express' policy on Cross-Posting in Rule 3: http://www.vbaexpress.com/forum/faq...._new_faq_item3
    Cheers
    Paul Edstein
    [MS MVP - Word]

  3. #3
    Banned VBAX Newbie
    Joined
    Sep 2019
    Posts
    4
    Location
    Hello,
    My sincere apologies, I posted it firstly on Stack but since nobody helped, I had to come here. I deleted the Stack post. I would really be more than grateful if someone could help here. Many thanks !

  4. #4
    Moderator VBAX Guru Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    3,826
    Location
    Your request to have this thread deleted has been considered and declined. Whether members here wish to assist you ( given that you have been noted to have cross posted) will be entirely at their discretion. You simply need to accept responsibility for your actions and if others think you are contrite enough then assistance may be offered.
    Remember To Do the Following....
    Use tags when posting code to the thread,
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    Banned VBAX Newbie
    Joined
    Sep 2019
    Posts
    4
    Location
    Quote Originally Posted by Aussiebear View Post
    Your request to have this thread deleted has been considered and declined. Whether members here wish to assist you ( given that you have been noted to have cross posted) will be entirely at their discretion. You simply need to accept responsibility for your actions and if others think you are contrite enough then assistance may be offered.
    Hello, Yes, I understood, please accept my sincere apologies, I should have deleted the Stack before posting here. If someone would be able to help with the above query I would be more than grateful.

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,891
    Location
    Quote Originally Posted by nigel1 View Post
    I posted it firstly on Stack but since nobody helped, I had to come here.
    Your StackOverflow thread had numerous responses when I looked...
    Cheers
    Paul Edstein
    [MS MVP - Word]

  7. #7
    Banned VBAX Newbie
    Joined
    Sep 2019
    Posts
    4
    Location
    Quote Originally Posted by macropod View Post
    Your StackOverflow thread had numerous responses when I looked...
    Hello, cheers for the reply.
    I was given some suggestion but they were sort of unclear to me anyway. Would anyone here be able to help based on the above code? I would really appreciate that.
    Last edited by nigel1; 09-17-2019 at 02:23 AM.

  8. #8
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,891
    Location
    Also cross-posted at: https://www.excelguru.ca/forums/show...table-to-Excel

    As per the forum rules, kindly provide links to all your cross-posts.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  9. #9
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,891
    Location
    Now also cross-posted at: https://stackoverflow.com/questions/...y-from-the-1st
    Clearly, you have utter contempt for this forum's rules and any other you might care to visit. Thread closed. Account terminated.
    Cheers
    Paul Edstein
    [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
  •