+ Reply to Thread
Results 1 to 4 of 4

How can I make this excel to word content control code more efficient?

  1. #1
    Registered User
    Join Date
    08-11-2022
    Location
    US
    MS-Off Ver
    2013
    Posts
    7

    How can I make this excel to word content control code more efficient?

    I am using the code block below to transfer spreadsheet data into word content controls. This works in theory (and worked well with a small dataset) but is unbelievably slow since I expanded it to this larger dataset (like ~45 minutes). Some potentially relevant context:

    - The word document with the content controls is a legacy doc within my organization and I have limited capacity to change it (e.g., I can change tags/names or other behind the scenes things, but other people tab through the content controls to do manual entry and I can't do anything that would screw that up or overtly change the appearance).

    - the 'dsData' dataset represents a row in an excel speadsheet with 563 columns. Not all columns will have values in any particular row, and each single row instance is likely to have 200-300 columns with values. However, the specific columns with values vary a lot across row instances so it's not like I can base my code around predictable subgroupings of the 563 values.

    - I don't really know what I'm doing. I sort of squished this together from various sources I found online and I'm hoping there is an obvious solution. It seems like there is a problem of large scale double iteration here but I'm not sure what to fix and had trouble directly googling this issue. Some things I would be interested in if they are technically feasible:

    1. can I improve my first if statement to exclude cells with formulas but no actual value (i.e., I think this is only skipping over truly blank cells, but a lot of cells in any particular row will have formulas but no specific value)
    2. can I drop out 'used' values in subsequent iterations (i.e., after I get a 'hit' for a CC.Title = dsData(i) match, can i somehow drop that particular value out of subsequent iterations?)
    3. would using 'i' and 'j' counts instead of 'i' and 'each cc in activedocument.contentcontrols' have any practical value here?
    4. Is there some completely different approach that would be more efficient?


    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,963

    Re: How can I make this excel to word content control code more efficient?

    It might work better if you put the row of data into an array and then looped through the cc titles once.

    Untested, but something along these lines.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-11-2022
    Location
    US
    MS-Off Ver
    2013
    Posts
    7

    Re: How can I make this excel to word content control code more efficient?

    Thank you, I experienced a slight improvement with this code (i.e., run time went from approximately 45 minutes to approximately 45 seconds). Made minor edits as below, which seem to work without the transposition step (will update if it blows up in my face though). Many, many thanks.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,963

    Re: How can I make this excel to word content control code more efficient?

    Great result. Thank you for the feedback.

+ 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. Trouble looping through content control blocks in MS Word to then export to Excel
    By mascon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-09-2020, 11:30 AM
  2. [SOLVED] Make code more efficient to prevent Excel from becoming unresponsive
    By Ianmacros in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-22-2019, 11:00 AM
  3. Count checked fieldform and content control boxes from word using excel
    By morganhughes360 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2015, 06:39 AM
  4. Excel Populating Microsoft Word Content Control DropDownList
    By Shanewjj in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-23-2014, 03:31 PM
  5. [SOLVED] Pull data to Word control content from Excel spreadsheet
    By coopman64 in forum Excel General
    Replies: 2
    Last Post: 06-30-2014, 10:05 PM
  6. Replies: 0
    Last Post: 07-02-2013, 08:40 AM
  7. VBA/Word picture content control causing unreadable content
    By atycks in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-15-2013, 04:51 PM

Tags for this Thread

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