![]() |
#1
|
|||
|
|||
![]()
Hi guys,
I am have a small problem which I was unable to solve for days now. I would be glad if you could give me some hints. I am somewhat experienced in VBA for Excel and Access. But this time I am struggling with Word. Here is what I have: Imagine I have a set of word documents where certain parts of the document need to be removed. I know the files and I know what needs removal. Luckily it is always a full page or multiple pages that need to go. So I know how to parse through the files and so on. But I can not make a successful full page delete. I try like this: Code:
Public Sub test() Dim x As Document ActiveDocument.SaveAs "e:\temp\test.docm" ' please don't mind this, it is just here for testing Set x = Documents.Open("e:\temp\test.docm") ' this also ' imagine I want to everything before Page 3 and after Page 5 DeleteBefore x, 3 DeleteAfter x, 2 x.Save End Sub Public Sub DeleteBefore(ByRef doc As Document, ByVal page_num As Long) Dim Rng As Range If page_num <= 1 Then _ Exit Sub With doc Set Rng = .GoTo(wdGoToPage, , , 1) Set Rng = Rng.GoTo(wdGoToPage, , , page_num) Rng.Delete End With End Sub Public Sub DeleteAfter(ByRef doc As Document, ByVal page_num As Long) Dim Rng As Range Dim max_page As Long max_page = doc.Content.ComputeStatistics(wdStatisticPages) If page_num >= max_page Then _ Exit Sub With doc Set Rng = .GoTo(wdGoToPage, , , page_num + 1) Set Rng = Rng.GoTo(wdGoToPage, , , max_page) Rng.Delete End With End Sub ![]() Thanks O.o nullLF |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Numbering with heading is mixed up in odd pages in regard to even pages | Baflla | Word | 0 | 09-11-2016 05:25 AM |
Multiple Master Pages dont sync with content pages | generatorjoe | Publisher | 0 | 07-28-2016 10:12 AM |
Remove Compatibility Mode on DOCX files (batch) | w64bit | Word | 17 | 02-01-2015 06:02 AM |
![]() |
Albus | Word | 12 | 12-12-2014 01:36 PM |
How to remove password from .docx file? | erik2282 | Word | 3 | 05-29-2012 05:44 AM |