VBA - Delete pages in Word based on Excel cell values

TBR68

New Member
Joined
Jul 4, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello,

I built a VBA that allows me to export multiple data fields from my Excel file to a Word file, using a Word template and bookmarks.
However, it happens that some bookmarks remain empty because there is no data in my data fields in Excel. However, when the template is launched, the pages without data are still displayed. The bookmark appears but is not replaced by my Excel data.

To avoid any further action from the users of this file, I would like to find a code that would remove the pages without much interest.

On this same forum, I could find this link which is close to my need, except that in this case, only the bookmarks are deleted and not the pages: VBA - Delete Bookmark Text in Word based on Excel cell values

Please find below a sample of my Excel sheet which indicates the pages to keep and to delete.

Word BookmarksPages with content = 1 / Pages to remove = 0
OVER11
OVER500
OVER510
.... (more than 60 pages w/ bookmarks in total)

Thanks :)
 

Attachments

  • 1656954765356.png
    1656954765356.png
    12.4 KB · Views: 6

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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