ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to delete the word document page programatically?

i am using Report generation toolkit and i made a template of 2 page, first page i made for test 1 and second page i made for test 2,

 

for some testing want to generate the report test1 and test 2.

 

for some testing want to generation the report test 1 only, that time i want to delete the second page.

 

how to do this?

 

attached template.

Regards,
Balaji DP
0 Kudos
Message 1 of 3
(3,936 Views)

It would be a lot easyer if you use Excel, you could then delete a sheet. Since there is no Page object in Word it is a lot more difficult. A possibility (there is probably a better way to do it) would be to insert a section break (next page) to separate you pages instead of pressing the enter key repeatably (which is a bad habit). You can then call the _Document-> Sections collection to get a reference  to section index 2 (your second page). Get the Range property of this section and then apply the Delete method.

 

You now have to remove the section break. Get a reference to the first section (index 1). Get the Range property of this Section and get the Find property of this range and then apply the Find method with ^b to the FindText input (^b is a section break) and an empty string constant to the ReplaveWith input. Et voilà.

 

Ben64

0 Kudos
Message 2 of 3
(3,903 Views)

It is possible to do it but for me it doesn't make a lot of sense since you can cut a paragraph or a sentence in the middle. If you had google it you would have found answers of how it can be done in VBA. Here is a LabVIEW adaptation of what I found:

 

Word Delete Specific Page.png

Ben64

0 Kudos
Message 3 of 3
(3,530 Views)