1.Word VBA中,如何根据内容删除一行
Sub DelBlank() Dim i as Paragraph, n as Long Application.ScreenUpdating = False For Each i In ActiveDocument.Paragraphs If Len(i.Range) = 1 Then i.Range.Delete n = n + 1 End If Next MsgBox "共删除空白段落" & n & "个。
" Application.ScreenUpdating = TrueEnd Sub摘自 EXCELHOME。
2.如何用vba批量删除指定文件夹中所有word文档的第1、2、6页
使用Dir函数,把你的文件夹中的word文档名全部找出来。
然后用documents.open方法,逐个打开文档改字体颜色。参考:Dim MyDoc$MyDoc = Dir("C:\Documents and Settings\user\My Documents\*.doc")Debug.Print MyDocDo While MyDoc <> "" MyDoc = Dir Debug.Print MyDocLoopopen方法是这样:Documents.Open FileName:=ThisDocument.Path & "\" & MyDoc你自己整合一起吧,这就不多说了。
你的那些关键字,没必要用字典保存啊,用Array函数更方便了。Dim KeyWords as VariantKeyWords=Array("关键词1",“关键词2”,……)。
3.VBA怎么删除文本文件
思路如下
1、选择文件路径
2、以下方法是清空文本文件用的
Sub mysub()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fso, f, ts
Set fso = CreateObject("Scripting.FileSystemObject")
Dim fullName As String
fullName = "D:\1.txt"
fso.createtextfile fullName
Set f = fso.getfile(fullName)
Set ts = f.openastextstream(ForWriting, TristateTrue)
ts.write "你好"
ts.Close
Set ts = Nothing
Set f = Nothing
Set fso = Nothing
End Sub3 整个文件删除用 kill 文件名 就可以。
4.批量删除word中的某一页(求VBA代码)
Public StartPageNum As Integer, EndPageNum As IntegerSub aaa() Dim myDialog As FileDialog, oFile As Variant, oDoc As Document On Error Resume Next Set myDialog = Application.FileDialog(msoFileDialogFilePicker) myDialog.Filters.Clear '清除所有文件筛选器中的项目 myDialog.Filters.Add "所有 WORD 文件", "*.doc", 1 '增加筛选器的项目为所有WORD文件 myDialog.AllowMultiSelect = True '允许多项选择 If myDialog.Show -1 Then Exit Sub Dim SelectRange As Range DlgDelePage.Show vbModal If StartPageNum = 0 And EndPageNum = 0 Then Exit Sub End IfFor Each oFile In myDialog.SelectedItems '在所有选取项目中循环 Set oDoc = Documents.Open(FileName:=oFile, Visible:=True) 'False)Dim Pages As Integer, StartPage As Long, EndPage As Long Pages = Selection.Information(wdNumberOfPagesInDocument) If Not (StartPageNum > Pages) Then If EndPageNum > Pages Then EndPageNum = Pages If StartPageNum = 1 Then StartPage = Selection.Range Else StartPage = Selection.GoTo(What:=wdGoToPage, Which:=wdGoToNext, Count:=StartPageNum - 1).Start End If If EndPageNum = Pages Then EndPage = ActiveDocument.Content.End Else EndPage = Selection.GoTo(What:=wdGoToPage, Which:=wdGoToNext, Count:=IIf(EndPageNum - StartPageNum > 0, EndPageNum - StartPageNum + 1, 1)).End '.Start End If ActiveDocument.Range(StartPage, EndPage).Select Selection.Delete End If '删除第3页批注 ActiveDocument.Words(1).Select '将光标移到文档开始位置 Dim myRange As Range, oComment As Comment Set myRange = Selection.Range StartPage = Selection.GoTo(What:=wdGoToPage, Which:=wdGoToNext, Count:=3 - 1).Start EndPage = Selection.GoTo(What:=wdGoToPage, Which:=wdGoToNext, Count:=3 - 1).End myRange = ActiveDocument.Range(StartPage, EndPage) If myRange.Comments.Count > 0 Then For Each oComment In myRange.Comments oComment.Delete Next End If oDoc.Save oDoc.Close Next oFileEnd Sub。
5.如何用vba批量删除指定文件夹中所有word文档的第1、2、6页
使用Dir函数,把你的文件夹中的word文档名全部找出来。然后用documents.open方法,逐个打开文档改字体颜色。
参考:
Dim MyDoc$MyDoc = Dir("C:\Documents and Settings\user\My Documents\*.doc")Debug.Print MyDocDo While MyDoc <> "" MyDoc = Dir Debug.Print MyDocLoop
open方法是这样:
Documents.Open FileName:=ThisDocument.Path & "\" & MyDoc
你自己整合一起吧,这就不多说了。
你的那些关键字,没必要用字典保存啊,用Array函数更方便了。
Dim KeyWords as Variant
KeyWords=Array("关键词1",“关键词2”,……)
转载请注明出处51数据库 » vba清空word中的文本