根据选择列表格式化单词doc [英] Formatting word doc based on selection list

查看:65
本文介绍了根据选择列表格式化单词doc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个糟糕的标题。

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()

Sub format_acllog()

    Dim COMMAND_LIST As String

    Dim i As Variant

    Dim v_color As String

           

    COMMAND_LIST =" @ ACCEPT,@ COMMENT,@ COM,记录产生,记录计数,匹配过滤器,@ DEFINE,@ SET FILTER,@ EXTRACT,@ SAMPLE"

   

   使用选择

        .WholeStory

        .Font.Name =" Courier New" $
        .Font.Size = 10

        .Paragraphs.Indent

   结束

    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

   对于i = 0到UBound(拆分(COMMAND_LIST,","))

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

       选择案例i'拆分(COMMAND_LIST,",")(i)

           案例0至2'" @ ACCEPT"

                v_color = wdRed

           案例3至5''产生的记录"或者"或"记录计数"或者"或"匹配过滤器"

                v_color = wdYellow

           案例6'"@ DEFINE"&
                v_color = wdPink

           案例7'" @ SET FILTER"&
                v_color = wdTurquoise

           案例8''@ EXTRACT"

                v_color = wdBrightGreen

           案例9''@ SAMPLE"

                v_color = wdTeal

           案例等等
                v_color = wdTeal

       结束选择

        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

       使用选择

            .Find.Text =拆分(COMMAND_LIST,",")(i)

           

            .ParagraphFormat.SpaceBefore = 6

            .Shading.BackgroundPatternColor = v_color

            .Find.Execute Replace:= wdReplaceAll

       结束与$
   下一步

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

结束子

示例日志:

@@ Log File \\Midf2fpw02411p\mi411-redirected\sjs596\Documents\projects \\ \ nUNIX \UNUN人口发展.LOG于2017年11月13日16:08:27开放 
_COMPLETED

忽略来自'_COMPLETED'的剩余行。

@ SET SAFETY ON

16:08: 27 - 11/13/2017  
$


@ COMMENT END SCRIPT:  Format_UNIX_Server_list

16:08:27 - 11/13/2017  

@ COMMENT - 执行Format_UNIX_Server_list已完成

16:08:27 - 11/13/2017  

@ CLOSE SECONDARY

16:10:38 - 11/13/2017  

结账文件:PRIOR_SERVER_LISTING.FIL

@ CLOSE

16:14:08 - 11/13/2017 &NBSP; @@ Log File \\Midf2fpw02411p\mi411-redirected\sjs596 \Documents\projects\UNIX\UNIX Population Development.LOG于2017年11月15日10:45:25开放<跨度>&NBSP;


@ OPEN UNIX_SERVERS_wAPP_INFO

10:45:25 - 11/15/2017  

激活了16个字段

打开文件名UNIX_SERVERS_wAPP_INFO.FIL,如表格布局所示。

@@ Log File \ \ Midf2fpw02411p\mi411-redirected\sjs596 \Documents\projects\UNIX\UNIX Population Development.LOG于2017年11月15日11:44:00开放 


@ DO Format_UNIX_Server_list

14:09:51 - 11/15/2017  

@ COMMENT

14:09:51 - 11/15/2017  

  SCRIPT:<跨度>&NBSP; Format_UNIX_Server_list

  CREATED:<跨度>&NBSP; SMS <跨度>&NBSP; 11/09/2017

  来自:
  更改日志:
$
结束



@ SET SAFETY OFF

14:09:51 - 2017年11月15日<跨度>&NBSP;

@ SET SESSION

14:09:51 - 11/15/2017  

@@ Log File \\Midf2fpw02411p\mi411-redirected\sjs596\Documents\projects\UNIX\UNIX Population Development.LOG于14:09开放:2017年11月15日星期五  


@ 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"Excel文件上的日期是什么(使用相同的格式)" 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  

'EXTERAND_UNIX_SERVER_TMP'未定义





@ SET FOLDER / SOURCE_FILES

14:09:51 - 11/15/2017  



@ OPEN UNIX_SERVERS_wAPP_INFO

14:09:51 - 11/15/2017  

激活了16个字段

在表格布局中打开文件名UNIX_SERVERS_wAPP_INFO.FIL。



@ EXTRACT ALL TO PRIOR_SERVER_LISTING

14:09:51 - 11/15/2017  

1073条记录生成

提取到表格\\Midf2fpw02411p \mi411-redirected\sjs596 \ Files \ project] \ nUNIX \ PRIOR_SERVER_LISTING.FIL已完成

@@ 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

推荐答案

尝试:

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


这篇关于根据选择列表格式化单词doc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆