Consulting

Results 1 to 4 of 4

Thread: Find and replace if specific conditions aply

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    May 2023
    Posts
    2
    Location

    Question Find and replace if specific conditions aply

    I need help for checking citations. I have to check long documents if "cf." Is used correctly. I either need a way to highlight the brackets or sentences in which "cf." Is used or for the VBA to do it itself.
    If there is a "." Or any word in front of the bracket it needs "cf.". If there are quotation marks in front of the bracket there should be no "cf."
    For example this is correct:
    example. (cf. Weber 2010)
    Example (cf. Weber 2010)
    This is incorrect:
    Example" (cf. Weber 2010)
    Example. (Weber 2010)


    I tried something to highlight sentences with quotation marks, but it is not doing what I want, please help

    Sub CheckParentheses()
    ' CheckParentheses Makro
    Dim paragraph As paragraph
        Dim Doc As Document
    ' Set the document object to the active document
        Set Doc = ActiveDocument
    ' Loop through all paragraphs in the document
        For Each paragraph In Doc.Paragraphs
            ' Check if the paragraph has the "Standard" style and does not contain a parenthesis
            If paragraph.Style = "Standard" And InStr(paragraph.Range.Text, "(") = 0 And InStr(paragraph.Range.Text, ")") = 0 Then
                ' Highlight the paragraph in yellow
                paragraph.Range.HighlightColorIndex = wdYellow
            End If
        Next
    End Sub
    Last edited by Aussiebear; 05-08-2023 at 12:09 PM. Reason: Added code tags to supplied code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •