I'm quite new to VBA so forgive if I don't explain this well but I've got a Word 2013 document with commands to shade specified rows based on dropdown selections within the document.
Currently, I have it set to delete all shaded rows from the document before printing but I want to have an additional sub to delete all shaded rows before using the "Save As" function as well - I just can't figure out where my command is going wrong.
Here's the print command that's working:
Public Sub myApp_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
Dim d1 As Document
Set d1 = ActiveDocument
Dim tbl As Table, r As Row, c As Cell, rng As Range, t As Integer
Dim i As Integer, n As Integer
'table counter
t = 1
'cycle through each table
For Each tbl In d1.Tables
'row counter
n = tbl.Rows.Count
'cycle through the rows in the selected table
For i = 1 To n Step 1
'compare pattern fill, select those that are shaded and delete
If d1.Tables(t).Rows(i).Shading.Texture = wdTextureDarkDiagonalDown Then
d1.Tables(t).Rows(i).Delete
End If
Next
t = t + 1
Next
Here's the Save As command that is not working:
Public Sub myApp_DocumentBeforeSaveAs(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
Dim d1 As Document
Set d1 = ActiveDocument
Dim tbl As Table, r As Row, c As Cell, rng As Range, t As Integer
Dim i As Integer, n As Integer
'table counter
t = 1
'cycle through each table
For Each tbl In d1.Tables
'row counter
n = tbl.Rows.Count
'cycle through the rows in the selected table
For i = 1 To n Step 1
'compare pattern fill, select those that are shaded and delete
If d1.Tables(t).Rows(i).Shading.Texture = wdTextureDarkDiagonalDown Then
d1.Tables(t).Rows(i).Delete
End If
Next
t = t + 1
Next
I don't get any error codes, it just doesn't do anything to the shaded text. I appreciate anyone that can point me in the right direction!
question from:
https://stackoverflow.com/questions/65904432/delete-shaded-rows-before-save 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…