Closed Thread
Results 1 to 2 of 2

optimize code if possible

Hybrid View

mohadin optimize code if possible 07-01-2019, 06:16 AM
AliGW Re: optimize code if possible 07-01-2019, 06:18 AM
  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 failed
    [code] wdDoc.Tables(1).Cell(i, j).Range = array(i,j) [code]

    then I come up with this code, hope to have help to optimize it if possible
    Thanks a lot
    
    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

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,165

    Re: optimize code if possible

    Administrative Note:

    Unfortunately, this is a duplicate thread, and you are allowed only ONE thread per issue here. I am, therefore, closing this thread, but you may continue here in the original thread: https://www.excelforum.com/excel-pro...-possible.html
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. optimize code if possible
    By mohadin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-01-2019, 10:31 AM
  2. How can I optimize my code
    By viettest in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-08-2019, 05:02 PM
  3. [SOLVED] Optimize my VBA code
    By modytrane in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-07-2019, 11:25 AM
  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