none
Formatting word doc based on selection list RRS feed

  • Question

  • That is probably a terrible title for this.

    I have a log file from a data analysis program, and for documentation, I want to highlight the entire paragraph of certain key phrases, but use a different color for each.

    I tried to use this code, but way off, I don't know the approach at all, any help?

    Sub format_acllog()

        Dim COMMAND_LIST As String
        Dim i As Variant
        Dim v_color As String
               
        COMMAND_LIST = "@ ACCEPT,@ COMMENT,@ COM ,records produced,records counted,matched the Filter,@ DEFINE,@ SET FILTER,@ EXTRACT,@ SAMPLE"
       
        With Selection
            .WholeStory
            .Font.Name = "Courier New"
            .Font.Size = 10
            .Paragraphs.Indent
        End With

        For i = 0 To UBound(Split(COMMAND_LIST, ","))

            Select Case i 'Split(COMMAND_LIST, ",")(i)
                Case 0 To 2 '"@ ACCEPT"
                    v_color = wdRed
                Case 3 To 5 '" records produced" Or " records counted" Or " matched the Filter"
                    v_color = wdYellow
                Case 6 '"@ DEFINE"
                    v_color = wdPink
                Case 7 ' "@ SET FILTER"
                    v_color = wdTurquoise
                Case 8 ' "@ EXTRACT"
                    v_color = wdBrightGreen
                Case 9 ' "@ SAMPLE"
                    v_color = wdTeal
                Case Else
                    v_color = wdTeal
            End Select

            With Selection
                .Find.Text = Split(COMMAND_LIST, ",")(i)
               
                .ParagraphFormat.SpaceBefore = 6
                .Shading.BackgroundPatternColor = v_color
                .Find.Execute Replace:=wdReplaceAll
            End With
        Next

    End Sub

    Example log:

    @@ Log File \\Midf2fpw02411p\mi411-redirected\sjs596\Documents\projects\UNIX\UNIX Population Development.LOG Opened at 16:08:27 on 11/13/2017  _COMPLETED
    Remainder of line from '_COMPLETED' ignored.
    @ SET SAFETY ON
    16:08:27 - 11/13/2017 

    @ COMMENT END SCRIPT:  Format_UNIX_Server_list
    16:08:27 - 11/13/2017 
    @ COMMENT - Execution of Format_UNIX_Server_list completed
    16:08:27 - 11/13/2017 
    @ CLOSE SECONDARY
    16:10:38 - 11/13/2017 
    Closing file: PRIOR_SERVER_LISTING.FIL
    @ CLOSE
    16:14:08 - 11/13/2017  @@ Log File \\Midf2fpw02411p\mi411-redirected\sjs596\Documents\projects\UNIX\UNIX Population Development.LOG Opened at 10:45:25 on 11/15/2017 
    @ OPEN UNIX_SERVERS_wAPP_INFO
    10:45:25 - 11/15/2017 
    16 fields activated
    Opening file name UNIX_SERVERS_wAPP_INFO.FIL as supplied in the table layout.
    @@ Log File \\Midf2fpw02411p\mi411-redirected\sjs596\Documents\projects\UNIX\UNIX Population Development.LOG Opened at 11:44:00 on 11/15/2017 
    @ DO Format_UNIX_Server_list
    14:09:51 - 11/15/2017 
    @ COMMENT
    14:09:51 - 11/15/2017 
      SCRIPT:  Format_UNIX_Server_list
      CREATED:  SMS  11/09/2017
      CALLED FROM:
      CHANGE LOG:
    END

    @ SET SAFETY OFF
    14:09:51 - 11/15/2017 
    @ SET SESSION
    14:09:51 - 11/15/2017 
    @@ Log File \\Midf2fpw02411p\mi411-redirected\sjs596\Documents\projects\UNIX\UNIX Population Development.LOG Opened at 14:09:51 on 11/15/2017  
    @ SET DATE 'MM/DD/YYYY'
    14:09:51 - 11/15/2017 
    @   COM ****BEGIN SCRIPT:
    14:09:51 - 11/15/2017 

    @ SET DELETE_FILE ON
    14:09:51 - 11/15/2017 

    @ CLOSE SECONDARY
    14:09:51 - 11/15/2017 
    @ CLOSE PRIMARY
    14:09:51 - 11/15/2017 

    @ COM ACCEPT "What is the date on the Excel file (use same format)" to v_FILEDATE
    14:09:51 - 11/15/2017 
    @ v_FILEDATE = "02.27.17"
    14:09:51 - 11/15/2017 

    @ DELETE FORMAT EXPAND_UNIX_SERVER OK
    14:09:51 - 11/15/2017 
    @ DELETE "\\Midf2fpw02411p\mi411-redirected\sjs596\Documents\projects\UNIX\EXPAND_UNIX_SERVER.FIL" OK
    14:09:51 - 11/15/2017 
    @ DELETE FORMAT EXPAND_UNIX_SERVER_TMP OK
    14:09:51 - 11/15/2017 
    'EXPAND_UNIX_SERVER_TMP' is undefined


    @ SET FOLDER /SOURCE_FILES
    14:09:51 - 11/15/2017 

    @ OPEN UNIX_SERVERS_wAPP_INFO
    14:09:51 - 11/15/2017 
    16 fields activated
    Opening file name UNIX_SERVERS_wAPP_INFO.FIL as supplied in the table layout.

    @ EXTRACT ALL TO PRIOR_SERVER_LISTING
    14:09:51 - 11/15/2017 
    1073 records produced
    Extraction to table \\Midf2fpw02411p\mi411-redirected\sjs596\Documents\projects\UNIX\PRIOR_SERVER_LISTING.FIL is complete

    Friday, November 17, 2017 8:11 PM

All replies

  • Try:

    Sub Demo()
    Application.ScreenUpdating = False
    Dim ArrFnd(), ArrClr(), i As Long
    ArrFnd() = Array("\@ ACCEPT", "\@ COMMENT", "\@ COM>", "\@ DEFINE", "\@ SET FILTER", "\@ EXTRACT", "\@ SAMPLE", "records produced", "records counted", "matched the Filter")
    ArrClr() = Array(wdRed, wdTeal, wdTeal, wdPink, wdTurquoise, wdBrightGreen, wdTeal, wdYellow, wdYellow, wdYellow)
    For i = 0 To UBound(ArrFnd)
      With ActiveDocument.Range
        With .Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Text = ArrFnd(i)
          .Replacement.Text = ""
          .Forward = True
          .Wrap = wdFindStop
          .MatchWildcards = True
          .Execute
        End With
        Do While .Find.Found = True
          .ParagraphFormat.SpaceBefore = 6
          .Shading.BackgroundPatternColorIndex = ArrClr(i)
          .Collapse wdCollapseEnd
          .Find.Execute
        Loop
      End With
    Next
    Application.ScreenUpdating = True
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, November 17, 2017 9:03 PM
  • Hi AnotherBiggles,

    I can see that after creating this thread, you did not done any follow up on this issue.

    is your issue is solved?

    if yes, I suggest you to post your solution and mark it as an answer.

    if your issue is still exist then try to refer the suggestions given by the community members.

    if you have any further questions then let us know about that.

    we will try to provide further suggestions to solve the issue.

    this thread is still open and will remain open until you mark the answer.

    so please try to update the status of the issue on this thread and take appropriate action to keep this forum healthy and helpful.

    Thanks for your understanding.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 24, 2017 8:34 AM
    Moderator