View Single Post
 
Old 10-16-2020, 10:20 AM
ajgarrison ajgarrison is offline Windows 10 Office 2013
Novice
 
Join Date: Sep 2020
Posts: 14
ajgarrison is on a distinguished road
Default

Here is my codeof relevant snippets) - and I think you are right on the pages because this code is giving me very strange results.

Dim Wrd As New Word.Application

Set Wrd = CreateObject("Word.Application")

'Specify the path and name to the Word document.

Dim MergeDoc As String

MergeDoc = "S:\K Jones Only\WordMBR.docx"

'Open the document template, make it visible.

Wrd.Documents.Add MergeDoc
Wrd.Visible = True

Dim I As Integer
Dim xRange As Range
Dim xPage As String
Dim xArr
Dim xPageCount As Long
Dim xSplitCount As Long

Wrd.ScreenUpdating = False

If Format = "U1" Then
If Left(rst.Fields("Classification"), 1) = "C" Then 'UD is a control
xPage = "4,6,8,10,11,12,20,21,24,28,29,30,31,32,35,38,39,4 0,41,43,46,50,51,52,53,54,55,56,57,58,59,60,61"
MsgBox "U1-Control"
Else 'UD is not a controlled
xPage = "4,6,8,9,10,11,12,14,20,21,24,28,29,30,31,32,35,38 ,39,40,41,43,46,50,51,52,53,54,55,56,57,58,59,60,6 1,71,72,73,74"
MsgBox "U1-Not Controlled"
End If
End If

xArr = Split(xPage, ",")
xPageCount = UBound(xArr)
For I = xPageCount To 0 Step -1
Wrd.Selection.GoTo wdGoToPage, wdGoToAbsolute, xArr(I)
Wrd.ActiveDocument.Bookmarks("\Page").Range.Delete
Next
Wrd.ScreenUpdating = True


The end result of this code is I'm getting pages that I have specified to delete and I'm getting 2 page 21s.
So, clearly my approach is faulty.

Again, thank you all for the help.
Reply With Quote