VBA/Macros help for an Excel to Word document generator. Need to create and find/replace X tables, where X is the numberof rows TRUE in another sheet

miknic

New Member
Joined
Nov 7, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi Excel brains trust,

My company have created a Report generator using a spreadsheet + VBA/macros.

To use it, our employees fill in a row, select a template from a dropdown, enter the reference pertaining to it, and then click a "Create Document" button. The code then reads which template is required, creates a new Word doc from said template, and fills in the placeholders based on the row.

The code does the following steps:
  1. Check if template selected in Cell C1
  2. Check if reference was provided in Cell F1
  3. Check the template actually exists within the folder
  4. Find the data and where the data starts
  5. Opens the correct Word doc and start the find and replace process within the main body of the document
  6. It loops through and fine/replaces based on placeholders in row 3
  7. Special handler for text boxes
  8. End code

We're looking to level this up with some new data we have but aren't sure how to go about it. I will do my best to explain what we are trying to achieve.

We want an additional sheet within the workbook, where we can copy and paste technical data from another programme into. This would be deleted and done fresh with each new document, as does not need to stay there. When the doc is generated, we want it to pull these rows into the doc as a new table per row present. It's easy enough to do it for one table/row but we need it to return multiple tables based on how many rows there are. E.g. one new table per row present. Sometimes this it's 2 - sometimes it's 20.

Something like...
> check 'Sheet 3' for rows excluding the header
> counts how many rows have data
> create the table with the placeholders
> find and replace based on placeholders
> loop until all rows with data have a table

This would likely be in between step 6 and 7 in the code?

I'm really hoping this makes sense! Here's a screenshot of how the sheet is set up.

Thanks in advanced - let me know what else I need to post! Hoping to avoid posting the whole code due to work confidentiality purposes but maybe I can post redacted parts or send them in a message if required.

Regards,

Mik

P.s. our VBA/Macros skills would be considered Intermediate.
 

Attachments

  • Screenshot 2022-11-08 144240.jpg
    Screenshot 2022-11-08 144240.jpg
    74.7 KB · Views: 39
Unfortunately, there is no "buy a beer" feature here other than pass it on if you can assist others. Have fun with your testing. Dave
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,223,882
Messages
6,175,165
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top