+ Reply to Thread
Results 1 to 3 of 3

optimize code if possible

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    optimize code if possible

    Hi all,
    good morning

    I aim to populate word existing table from an excel rang.
    I'd prefer to use excel range to array and pass it to the word table rather than copy each cell and paste it to word table.
    then I come up with this code hope to have help to optimize
    I was trying for this method but I faild
       wdDoc.Tables(1).Cell(i, j).Range = array(i,j)
    then I come up with this code, hope to have help to optimize
    
    Sub xl_Rng2Word_table()
    
        Dim appWord As Word.Application
        Dim wordDoc As Word.Document
        Dim rng As Range
        Dim sh_source As Worksheet
        Dim wdApp As Word.Application
        Dim wdDoc As Word.Document
    
        Set sh_source = ThisWorkbook.Sheets("sheet1")
        Set rng = sh_source.Range("a1:j21")
        vaData = rng
        u = UBound(vaData, 1)
        l = UBound(vaData, 2)
    
    
        Set wdApp = New Word.Application
        wdApp.Visible = True
        Set wdDoc = wdApp.Documents.Open(ThisWorkbook.Path & "\" & "3333.docx")
        j = 1
        For Each Cel In wdDoc.Tables(1).Range.Cells
            i = i + 1
            Count = Count + 1
            Cel.Range.Text = vaData(j, i)
            If i = l Then
                i = 0
                j = j + 1
            End If
            If j = u + 1 Then Exit For
        Next Cel
    
    End Sub
    Last edited by mohadin; 07-01-2019 at 07:59 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: optimize code if possible

    Hi AliGW,
    realy I don't know what append, please accept my appology

    Thank you

  3. #3
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: optimize code if possible

    Any chance?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How can I optimize my code
    By viettest in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-08-2019, 05:02 PM
  2. [SOLVED] Optimize my VBA code
    By modytrane in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-07-2019, 11:25 AM
  3. Need to optimize the code
    By pm.patel189 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-05-2018, 01:06 PM
  4. Optimize a code
    By pezalmendra in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-06-2015, 05:31 PM
  5. Optimize code
    By DarkKnightLupo in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 02-19-2014, 08:58 AM
  6. Optimize code
    By miso.dca in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-08-2011, 03:35 PM
  7. Optimize VBA code
    By doodlebug in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2007, 07:53 AM

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