word如何提取某几段首尾加中括号?
来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/05/26 00:34:53
word如何提取某几段首尾加中括号?
请问:一个word里有100段话,如何给不含有:(冒号)的那几段首尾统一加上中括号【】?
请问:一个word里有100段话,如何给不含有:(冒号)的那几段首尾统一加上中括号【】?
'如果段落过长程序运行时间可能很长,注意看状态栏写的进度,代码在2013版Word初步测试无误,其余版本若存在不兼容问题请追问
'代码导入方法:
'打开你要操作的Word文档主UI按{Alt+F11}进入VBE,在左边的任意位置右键单击鼠标选择插入、模块,将此代码复制进去,关闭VBE,按{Alt+F8}选择Test并运行
'注意事项:程序运行完成会弹出End的对话框,此对话框弹出之前勿在Word中单击鼠标,可以将其最小化等待(标题栏可以单击),否则程序可能出现不可预知的错误
Sub test()
Dim para As String, length As Long, i As Long, f As Field, j As Long, h As Boolean
Application.ScreenUpdating = False
Application.StatusBar = "Preparing"
For j = 1 To ActiveDocument.Paragraphs.Count
Application.StatusBar = Int(j / (ActiveDocument.Paragraphs.Count / 100)) & " percent finished"
para = ActiveDocument.Paragraphs(j).Range
length = Len(para)
h = False
For i = 1 To length - 1
If Mid(para, i, 1) = ":" Then
h = True
Exit For
End If
Next
If h = True Then
ActiveDocument.Paragraphs(j).Range.Select
Selection.MoveLeft , 1
Selection.TypeText "【】"
ActiveDocument.Paragraphs(j).Range.Select
Selection.MoveRight , 1
Selection.MoveLeft , 1
Selection.TypeText "【】"
End If
Next
Application.StatusBar = "Finishing"
Application.ScreenUpdating = True
Application.StatusBar = "End"
MsgBox "End!", vbInformation, "test"
End Sub
再问: 首先谢谢你!我想表达的意思是,一篇文章里很多段话,有些是有人讲述的,有些不是,我想把不是人说话的那一段前后加上中括号。标题保留不变
例如:
第一集 心情
今天A心情不好。
B:为什么你今天心情不好?
A:因为天气阴沉沉的,我也感到很郁闷。
B塞给A一块糖。
改成:
第一集 心情
【今天A心情不好。】
B:为什么你今天心情不好?
A:因为天气阴沉沉的,我也感到很郁闷。
【B塞给A一块糖。】
再答: Sub test()
Dim para As String, length As Long, i As Long, f As Field, j As Long, h As Boolean
Application.ScreenUpdating = False
Application.StatusBar = "Preparing"
For j = 1 To ActiveDocument.Paragraphs.Count
para = ActiveDocument.Paragraphs(j).Range
length = Len(para)
h = False
For i = 1 To length - 1
If Mid(para, i, 1) = ":" Then
h = True
Exit For
End If
Next
If h = False Then
ActiveDocument.Paragraphs(j).Range.Select
Selection.MoveLeft , 1
Selection.TypeText "【"
ActiveDocument.Paragraphs(j).Range.Select
Selection.MoveRight , 1
Selection.MoveLeft , 1
Selection.TypeText "】"
End If
Next
Application.StatusBar = "Finishing"
Application.ScreenUpdating = True
Application.StatusBar = "End"
MsgBox "End!", vbInformation, "test"
End Sub'标题如果不多的话手动去掉吧,或者用替换来去掉
再问: 谢谢!可能是我的页数太多,有几百页,大概等了20分钟还没运行好。这个是不是只要继续等下去就ok?
'代码导入方法:
'打开你要操作的Word文档主UI按{Alt+F11}进入VBE,在左边的任意位置右键单击鼠标选择插入、模块,将此代码复制进去,关闭VBE,按{Alt+F8}选择Test并运行
'注意事项:程序运行完成会弹出End的对话框,此对话框弹出之前勿在Word中单击鼠标,可以将其最小化等待(标题栏可以单击),否则程序可能出现不可预知的错误
Sub test()
Dim para As String, length As Long, i As Long, f As Field, j As Long, h As Boolean
Application.ScreenUpdating = False
Application.StatusBar = "Preparing"
For j = 1 To ActiveDocument.Paragraphs.Count
Application.StatusBar = Int(j / (ActiveDocument.Paragraphs.Count / 100)) & " percent finished"
para = ActiveDocument.Paragraphs(j).Range
length = Len(para)
h = False
For i = 1 To length - 1
If Mid(para, i, 1) = ":" Then
h = True
Exit For
End If
Next
If h = True Then
ActiveDocument.Paragraphs(j).Range.Select
Selection.MoveLeft , 1
Selection.TypeText "【】"
ActiveDocument.Paragraphs(j).Range.Select
Selection.MoveRight , 1
Selection.MoveLeft , 1
Selection.TypeText "【】"
End If
Next
Application.StatusBar = "Finishing"
Application.ScreenUpdating = True
Application.StatusBar = "End"
MsgBox "End!", vbInformation, "test"
End Sub
再问: 首先谢谢你!我想表达的意思是,一篇文章里很多段话,有些是有人讲述的,有些不是,我想把不是人说话的那一段前后加上中括号。标题保留不变
例如:
第一集 心情
今天A心情不好。
B:为什么你今天心情不好?
A:因为天气阴沉沉的,我也感到很郁闷。
B塞给A一块糖。
改成:
第一集 心情
【今天A心情不好。】
B:为什么你今天心情不好?
A:因为天气阴沉沉的,我也感到很郁闷。
【B塞给A一块糖。】
再答: Sub test()
Dim para As String, length As Long, i As Long, f As Field, j As Long, h As Boolean
Application.ScreenUpdating = False
Application.StatusBar = "Preparing"
For j = 1 To ActiveDocument.Paragraphs.Count
para = ActiveDocument.Paragraphs(j).Range
length = Len(para)
h = False
For i = 1 To length - 1
If Mid(para, i, 1) = ":" Then
h = True
Exit For
End If
Next
If h = False Then
ActiveDocument.Paragraphs(j).Range.Select
Selection.MoveLeft , 1
Selection.TypeText "【"
ActiveDocument.Paragraphs(j).Range.Select
Selection.MoveRight , 1
Selection.MoveLeft , 1
Selection.TypeText "】"
End If
Next
Application.StatusBar = "Finishing"
Application.ScreenUpdating = True
Application.StatusBar = "End"
MsgBox "End!", vbInformation, "test"
End Sub'标题如果不多的话手动去掉吧,或者用替换来去掉
再问: 谢谢!可能是我的页数太多,有几百页,大概等了20分钟还没运行好。这个是不是只要继续等下去就ok?