Simpatie.ro - matrimoniale
Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Nou pe simpatie:
Diana2019
Femeie
25 ani
Vaslui
cauta Barbat
25 - 80 ani
Mrrrr's Forum (VIEW ONLY)ReguliInregistrareLoginPozeNu sunteti logat. Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides /

[WORD] Delete Paragraph if its Shading is RGB [VBA]

Pagini: 1 Moderat de TRaP, TonyTzu
#1
TRaP
Moderator
Postari: 960
The following code deletes entire paragraphs in the active document that have the RGB: 184,221,241 color shading.
You can replace the values in RGB with your own.

Just open VBA from Word, make new module and paste the following:


Sub DeleteParagraphIfShading()
    Application.ScreenUpdating = False

Dim para As Paragraph
    For Each para In ActiveDocument.Paragraphs
   
    On Error Resume Next

        If para.Range.Shading.BackgroundPatternColor = RGB(184, 221, 241) Then
            para.Range.Delete
        End If
       
    Next

    Application.ScreenUpdating = True
End Sub


 
   
#2
TRaP
Moderator
Postari: 960
If you want, for example to shrink the text of a paragraph, you insert the following snippet inside the For function above:

    If para.Range.Shading.BackgroundPatternColor = RGB(255, 250, 250) Then
        para.Range.Font.Size = 5
    End If


 
   
#3
TRaP
Moderator
Postari: 960
Made a user form with 2 buttons, one called Dark Blue and another one called Lite Blue.

Command button 1 and 2 click takes you to:


Private Sub CommandButton1_Click()
Application.ScreenUpdating = False

Dim para As Paragraph

For Each para In ActiveDocument.Paragraphs
On Error Resume Next
    If para.Range.Shading.BackgroundPatternColor = RGB(184, 221, 241) Then
        para.Range.Delete
    End If
Next

Application.ScreenUpdating = True
End Sub

Private Sub CommandButton2_Click()
Application.ScreenUpdating = False

Dim para As Paragraph

For Each para In ActiveDocument.Paragraphs
On Error Resume Next
    If para.Range.Shading.BackgroundPatternColor = RGB(230, 249, 255) Then
        para.Range.Delete
    End If
Next

Application.ScreenUpdating = True
End Sub


Calling User Form with macro:


Sub ParagDeleteForm()
    ParagraphDeleteForm.Show
End Sub


 
   
Pagini: 1  
Mergi la