Results 1 to 1 of 1

Add data to table in word file

Threaded View

  1. #1
    Registered User
    Join Date
    11-27-2018
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    27

    Add data to table in word file

    Hi,

    I would like to code VBA form excel to add data to each cell of the table for the attached word file.

    I use following code:
    Sub Thu()
    
       Dim objWord
    
       Dim objDoc
    
       Dim intParaCount
    
       Dim objParagraph
    
       Set objWord = CreateObject("Word.Application")
    
       Set objDoc = objWord.Documents.Open("D:\X61\X61.docx")
    
       objWord.Visible = True
    
       intParaCount = objDoc.Paragraphs.Count
    
       'MsgBox intParaCount
    
       Set objParagraph = objDoc.Paragraphs(3).Range
    
         objParagraph.Find.Text = "y      th"
    
         Do
    
             objParagraph.Find.Execute
    
             If objParagraph.Find.Found Then
    
                objParagraph.Text = "y   20 th"
                
             End If
             
         Loop While objParagraph.Find.Found
         
         
        Set objParagraph = objDoc.Paragraphs(3).Range
         objParagraph.Find.Text = "g       n"
    
         Do
    
             objParagraph.Find.Execute
    
             If objParagraph.Find.Found Then
    
                objParagraph.Text = "g  11   n"
    
            End If
    
        Loop While objParagraph.Find.Found
        
        
        Set objParagraph = objDoc.Paragraphs(3).Range
         objParagraph.Find.Text = "mf"
    
         Do
    
             objParagraph.Find.Execute
    
             If objParagraph.Find.Found Then
    
                objParagraph.Text = "m 2020"
    
            End If
    
        Loop While objParagraph.Find.Found
        
        
        Set objParagraph = objDoc.Paragraphs(13).Range
         objParagraph.Find.Text = "1"
    
         Do
    
             objParagraph.Find.Execute
    
             If objParagraph.Find.Found Then
    
                objParagraph.Text = "ABC"
    
            End If
    
        Loop While objParagraph.Find.Found
        
        
    End Sub
    But I can only change data for the 1st row of the table.

    Please help me to change data for the 2nd row of the table.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Please help me Create new word file and copy table, data from excel
    By sbv1986 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-13-2019, 10:47 PM
  2. Create new Word file then Copy table and contents from Excel to that Word file
    By sbv1986 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-23-2018, 09:14 AM
  3. Extract Word header table data to excel (closed word document)
    By Yakov on Excel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-14-2017, 02:12 PM
  4. Pasting excel table one after another in Ms-Word file Using VBA code
    By manish_ti in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-19-2012, 02:06 PM
  5. Replies: 0
    Last Post: 06-15-2011, 02:22 PM
  6. Copy a Table from Word file to Excel
    By sure2005 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-19-2010, 11:37 PM
  7. Need Help in copying a Table from Word file to Excel
    By sure2005 in forum Excel General
    Replies: 1
    Last Post: 10-19-2010, 03:23 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1