精华内容
下载资源
问答
  • 分享成果,随喜真能量。大家好,今日内容仍是和大家分享VBA编程中常用的简单“积木”过程代码,这些内容大多是取至我编写的... 182:在VBA中使用FileCopy语句复制文件VBA过程代码180:在VBA中split和join对数组操作...

    34549e68be50db32a63d79a3d33973d5.png

    分享成果,随喜真能量。大家好,今日内容仍是和大家分享VBA编程中常用的简单“积木”过程代码,这些内容大多是取至我编写的“VBA代码解决方案”教程中内容。NO.176-NO.177容是:

    NO. 180:在VBA中split和join对数组操作

    NO. 181:在VBA中查找数组的差集

    NO. 182:在VBA中使用FileCopy语句复制文件

    VBA过程代码180:在VBA中split和join对数组操作

    321ec2c54de3ce767749af746001b9f4.png

    Sub mynz()

    Dim arr, myst As String

    myst = "A-REW-E-RWC-2-RWC"

    arr = Split(myst, "-")

    MsgBox arr(0)

    MsgBox Join(arr, ",")

    End Sub

    代码的解析说明:mynz过程使用split和join函数,显示数组的第一个数,再用","把数组的每个值连接成一个字符串。

    VBA过程代码181:在VBA中查找数组的差集

    2ef5f6d6baea2cc6cfd1b1e8b4c0d109.png

    Sub mynz()

    Dim varArr1 As Variant

    Dim varArr2 As Variant

    Dim i As Integer

    varArr2 = Array(1021, 1023, 1025)

    varArr1 = Array(1021, 1022, 1023, 1024, 1025, 1026, 1027, 1028)

    For i = 0 To UBound(varArr2)

    varArr1 = VBA.Filter(varArr1, varArr2(i), False)

    Next i

    MsgBox Join(varArr1)

    End Sub

    代码的解析说明:mynz过程实现varArr2,varArr1两个数组的差值。使用filter函数在此是模糊查找。

    VBA过程代码182:在VBA中使用FileCopy语句复制文件。

    1376fc606ba094906f17291d191b5dfe.png

    Sub mynz()

    Dim SourceFile As String

    Dim DestinationFile As String

    SourceFile = ThisWorkbook.Path & "VBA代码解决方案(1-48).docx"

    DestinationFile = ThisWorkbook.Path & "ABCabc.docx"

    FileCopy SourceFile, DestinationFile

    End Sub

    代码的解析说明:mynz过程使用FileCopy语句将示例文件所在文件夹中的"VBA代码解决方案(1-48).docx"文件复制到示例文件目录下的“ABC”文件夹中并重新命名为“abc.docx”。代码使用FileCopy语句复制文件。

    VBA是实现自己小型办公自动化的有效手段,我根据自己20多年的VBA实际利用经验,现推出了四部VBA教程,这些是我多年编程经验的记录,也是我“积木编程”思想的体现。每一讲都是较大块的“积木”,可以独立的完成某些或者某类的过程,有需要的朋友可以联络(WeChat:NZ9668)分享。利用这些可以提高自己的编程效率。其一:“VBA代码解决方案”PDF教程,是VBA中各个知识点的讲解,覆盖了绝大多数的知识点,是初学及中级以下人员必备;其二“VBA数据库解决方案”PDF教程,数据库是数据处理的利器,对于中级人员应该掌握这个内容了。其三“VBA数组与字典解决方案”PDF教程,讲解VBA的精华----字典,是我们打开思路,提高代码水平的必备。其四“VBA代码解决方案”视频教程。目前正在录制,“每天20分钟,半年精进VBA”,越早参与,回馈越多。现在录制到第三册的103讲,以上各教程的代码都是经过实测,可以拿来即用。

    展开全文
  • 查找文件vba

    2010-07-26 09:25:00
    Sub test() Dim MyFile, MyPath, MySz MyPath = "D:/Data/z/" ' 指定路径。' 显示 路径目录下的名称。... MySz = Dir ' 查找下一个目录。 Loop End Sub   谢谢啦~~~~~~~~~~~~~~~~~~~~

    Sub test()

    Dim MyFile, MyPath, MySz

    MyPath = "D:/Data/z/"    ' 指定路径。' 显示 路径目录下的名称。
    MySz = Dir(MyPath, vbDirectory)    ' 找寻第一项。
    Do While MySz <> ""    ' 开始循环。
        If MySz <> "." And MySz <> ".." Then ' 跳过当前的目录及上层目录。
            If (GetAttr(MyPath & MySz) And vbDirectory) = vbDirectory Then '' 使用位比较来确定 MyName 代表一目录。如果是则进入操作
                 MyFile = Dir(MyPath & MySz & "/*.xls") 'left(,8)??
             【=======  以下怎么判断日期最新的前5个xls文件名?==============】

                       xls文件名格式是  20071201abc.xls    20071202abc.xls    20071203abc.xls    20071205abc.xls 20071206abc.xls 等

     

             【=======  以上怎么判断日期最新的前5个xls文件名?==============】
             End If
        End If
        MySz = Dir    ' 查找下一个目录。
    Loop

    End Sub

     

    谢谢啦~~~~~~~~~~~~~~~~~~~~

    展开全文
  • 这是一个仿api调用方式的文件查找代码,在office 2010验证通过。 调用时,查到的文件直接在调用函数的参数中返回,调用时给出参数名称,函数自动返回数组结果。可以返回文件名,文件大小,创建日期,修改日期。 是在...
  • Sub 宏4() ' ' 宏4 宏 ...'循环读取文件 For i = 4276 To 4300 Dim strpath As String Dim strname As String Dim strall As String Dim ipath As Integer strpath = "C:\Users\Administrator
    Sub 宏4()
    '
    ' 宏4 宏
    '
    '
    '循环读取文件
    For i = 4276 To 4300
        Dim strpath As String
        Dim strname As String
        Dim strall As String
        
        Dim ipath As Integer
        
        strpath = "C:\Users\Administrator\Desktop\收 - 副本\"
        
        strname = "FIL"
        strname = strname & i & ".DOC"
        strall = strpath & strname
        
        
        Dim fs As Object
    Dim fname As String
    
    Set fs = CreateObject("Scripting.FileSystemObject")
    
    If fs.FileExists(strall) = False Then
    
    MsgBox "文件" & strall & "不存在!"
    
    End If
    
    
        
        ChangeFileOpenDirectory strpath
        Documents.Open FileName:=strname, ConfirmConversions:=False, _
            ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
            PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
            WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindAsk
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        ActiveDocument.SaveAs FileName:="二○○七年度新闻报道工作意见.doc", FileFormat:= _
            wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
            True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
            False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
            SaveAsAOCELetter:=False
    Next i
    End Sub
    Sub 宏1()
    '
    ' 宏1 宏
    '
    '
       Dim strt1 As String
       Dim strt1ALL As String
    
       Dim strt2 As String
       Dim strt2ALL As String
       
       Dim strtmp As String
       
       Dim bstr As Boolean
       
       bstr = False
       
       
    
           Dim strpath As String
        Dim strname As String
        Dim strall As String
        
        Dim ipath As Integer
        
        strpath = "C:\Users\Administrator\Desktop\收 - 副本\"
        
        strname = "FIL"
        strname = "FIL4284.DOC"
        strall = strpath & strname
        
        
        Dim fs As Object
    Dim fname As String
    
    Set fs = CreateObject("Scripting.FileSystemObject")
    
    If fs.FileExists(strall) = False Then
    
    MsgBox "文件" & strall & "不存在!"
    
    End If
    
    
        
        ChangeFileOpenDirectory strpath
        Documents.Open FileName:=strname, ConfirmConversions:=False, _
            ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
            PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
            WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
        Selection.Find.ClearFormatting
        
        
        
        For i = 0 To 500
        Selection.MoveRight Unit:=wdCharacter, Count:=1
        Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
        Selection.Copy
        
        mySel = Selection.Font.Size
        
        If mySel = 22 Then
       ' MsgBox "22."
        'strtmp = wdPasteDefault
        strt1 = Selection.Text
        Else
        'strtmp = wdPasteDefault
        strt2 = Selection.Text
        End If
        
        strt1ALL = strt1ALL & strt1
        strt2ALL = strt2ALL & strt2
        
        Next i
        Selection.Text = strt1ALL
        
        For j = 1 To 2
        
        
        Selection.Find.Execute FindText:="^p", ReplaceWith:=" ", _
            Format:=True, Replace:=wdReplaceAll
        
       ' Selection.Find.Execute FindText:="  ", ReplaceWith:=" ", _
        '    Format:=True, Replace:=wdReplaceAll
        
        strt1ALL = Selection.Text
        Next j
        
        Selection.Text = strt1ALL
        
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "^p"
            .Replacement.Text = " "
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        With Selection
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseStart
            Else
                .Collapse Direction:=wdCollapseEnd
            End If
            .Find.Execute Replace:=wdReplaceOne
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseEnd
            Else
                .Collapse Direction:=wdCollapseStart
            End If
            .Find.Execute
        End With
        With Selection
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseStart
            Else
                .Collapse Direction:=wdCollapseEnd
            End If
            .Find.Execute Replace:=wdReplaceOne
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseEnd
            Else
                .Collapse Direction:=wdCollapseStart
            End If
            .Find.Execute
        End With
        With Selection
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseStart
            Else
                .Collapse Direction:=wdCollapseEnd
            End If
            .Find.Execute Replace:=wdReplaceOne
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseEnd
            Else
                .Collapse Direction:=wdCollapseStart
            End If
            .Find.Execute
        End With
        With Selection
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseStart
            Else
                .Collapse Direction:=wdCollapseEnd
            End If
            .Find.Execute Replace:=wdReplaceOne
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseEnd
            Else
                .Collapse Direction:=wdCollapseStart
            End If
            .Find.Execute
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
        With Selection.Find
            .Text = "  "
            .Replacement.Text = " "
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        
        
        Selection.Find.ClearFormatting
        Selection.Text = strt1ALL
        
        For k = 1 To 100
        Selection.Find.Execute FindText:="  ", ReplaceWith:=" ", _
            Format:=True, Replace:=wdReplaceAll
        
       ' Selection.Find.Execute FindText:="  ", ReplaceWith:=" ", _
        '    Format:=True, Replace:=wdReplaceAll
        
        If Selection.Find.Text <> "  " Then
        
        i = 100
        End If
        
        
        strt1ALL = Selection.Text
        Next k
        
        
        
        
        
        
        Selection.PasteAndFormat (wdPasteDefault)
        
        
    End Sub
    Sub 宏2()
    '
    ' 宏2 宏
    '
    '
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Copy
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindAsk
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.Copy
        ActiveDocument.Save
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindAsk
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Copy
        Selection.Copy
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindAsk
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.Copy
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindAsk
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Copy
        Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindAsk
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindAsk
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.Find.Execute
    End Sub
    Sub 宏3()
    '
    ' 宏3 宏
    '
    '
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindAsk
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.Copy
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindAsk
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Windows("模版文件.doc [兼容模式]").Activate
        Selection.MoveDown Unit:=wdLine, Count:=3
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindAsk
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Windows("FIL4269.DOC [兼容模式]").Activate
    End Sub
    Sub 宏5()
    '
    ' 宏5 宏
    '
    '
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.PasteAndFormat (wdPasteDefault)
        Windows("模版文件.doc [兼容模式]").Activate
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "^p"
            .Replacement.Text = " "
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        With Selection.Find
            .Text = "  "
            .Replacement.Text = " "
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.WholeStory
        Selection.Copy
        Windows("FIL4269.DOC [兼容模式]").Activate
        ChangeFileOpenDirectory "C:\Users\Administrator\Desktop\收 - 副本\结果文件\"
        ActiveDocument.SaveAs FileName:="函 关于请求办理.doc" _
            , FileFormat:=wdFormatDocument, LockComments:=False, Password:="", _
            AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
            EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
            :=False, SaveAsAOCELetter:=False
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("函 关于请求办理函.doc [兼容模式]").Activate
        ActiveWindow.Close
        Selection.WholeStory
        Selection.Delete Unit:=wdCharacter, Count:=1
    End Sub
    Sub 宏6()
    '
    ' 宏6 宏
    '
    '
    For i = 4276 To 4300
    Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.Copy
        Selection.PasteAndFormat (wdPasteDefault)
        Windows("模版文件.doc [兼容模式]").Activate
    Next i
    End Sub
    Sub 宏7()
    '
    ' 宏7 宏
    '
    '
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.MoveRight Unit:=wdCharacter, Count:=38
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = True
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.Find.ClearFormatting
        Selection.Find.Font.Size = 22
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.MoveRight Unit:=wdCharacter, Count:=1
        Selection.MoveDown Unit:=wdLine, Count:=1
        Selection.MoveLeft Unit:=wdCharacter, Count:=9
        Selection.MoveRight Unit:=wdCharacter, Count:=2
        Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.MoveRight Unit:=wdCharacter, Count:=1
        Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
        Selection.MoveRight Unit:=wdCharacter, Count:=1
        Selection.MoveLeft Unit:=wdCharacter, Count:=1
        Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.MoveRight Unit:=wdCharacter, Count:=1
        Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.MoveRight Unit:=wdCharacter, Count:=1
        Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
        Selection.Copy
        Windows("模版文件.doc [兼容模式]").Activate
        Windows("FIL4269.DOC [兼容模式]").Activate
        Selection.PasteAndFormat (wdPasteDefault)
    End Sub
    Sub 宏8()
    '
    ' 宏8 宏
    '
    '
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "  "
            .Replacement.Text = " "
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.WholeStory
        Selection.Delete Unit:=wdCharacter, Count:=1
        Selection.Paste
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "^p"
            .Replacement.Text = " "
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        With Selection
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseStart
            Else
                .Collapse Direction:=wdCollapseEnd
            End If
            .Find.Execute Replace:=wdReplaceOne
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseEnd
            Else
                .Collapse Direction:=wdCollapseStart
            End If
            .Find.Execute
        End With
        With Selection
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseStart
            Else
                .Collapse Direction:=wdCollapseEnd
            End If
            .Find.Execute Replace:=wdReplaceOne
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseEnd
            Else
                .Collapse Direction:=wdCollapseStart
            End If
            .Find.Execute
        End With
        With Selection
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseStart
            Else
                .Collapse Direction:=wdCollapseEnd
            End If
            .Find.Execute Replace:=wdReplaceOne
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseEnd
            Else
                .Collapse Direction:=wdCollapseStart
            End If
            .Find.Execute
        End With
        With Selection
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseStart
            Else
                .Collapse Direction:=wdCollapseEnd
            End If
            .Find.Execute Replace:=wdReplaceOne
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseEnd
            Else
                .Collapse Direction:=wdCollapseStart
            End If
            .Find.Execute
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
        With Selection.Find
            .Text = "  "
            .Replacement.Text = " "
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    

    展开全文
  • 将需要查找所有文件的文件夹地址赋给数组,成为arr(1) 2.使用folder.subfolders属性将子文件夹继续赋给数组,成为arr(i) 3.使用folder.files属性访问所有文件夹内的文件 核心算法就是,将子文件夹地址不断加入...

    整体思路是:
    1.将需要查找所有文件的文件夹地址赋给数组,成为arr(1)
    2.使用folder.subfolders属性将子文件夹继续赋给数组,成为arr(i)
    3.使用folder.files属性访问所有文件夹内的文件
    核心算法就是,将子文件夹地址不断加入数组,然后遍历数组中的每一个地址访问文件

    首先需要添加引用:Microsoft Scripting runtime
    在这里插入图片描述
    添加用在这里插入图片描述

    Sub 所有文件夹()
    Dim fs As New FileSystemObject, arr(), i, j, k
    Dim fd, subfd As Folder
    Dim files As file
    Set fp = Application.FileDialog(msoFileDialogFolderPicker) '选择需要查询文件的文件夹
    fp.Show
    Set paths = fp.SelectedItems
    ReDim arr(1)
    arr(0) = paths(1) '文件夹路径赋给数组
    Application.ScreenUpdating = False
    Do Until i > k
        Set fd = fs.GetFolder(arr(i))
        For Each files In fd.files
            j = j + 1
            Range("a" & j + 1).Hyperlinks.Add Anchor:=Range("a" & j + 1), Address:=files.path, TextToDisplay:=files.Name
            Range("b" & j + 1) = files.DateLastModified
            Range("C" & j + 1) = files.Size \ 1024 & "KB"
        Next
        For Each subfd In fd.SubFolders
            k = k + 1
            ReDim Preserve arr(k + 1)
            arr(k) = subfd  ’将子文件夹赋给数组
        Next
        i = i + 1
    Loop
    MsgBox ("一共有" & j & "个文件," & k & "个文件夹")
    Application.ScreenUpdating = True
    End Sub
    
    
    
    
    
    展开全文
  • Function findAndCopy(srcFile As String, destFile As String, cmdFile As String) Dim WSH As Object, wExec As Object, result Dim val, n Dim i As Integer Dim sFile As Object, Fso As ...
  • 大家好,我们今日继续讲解VBA代码解决方案的第80讲内容:如何查找文件。总是在讲解VBA,其实VBA真的功能强大,但也有他自身的不足,我的感觉,如果是处理一些数据的统计,归类之类的问题,VBA的作用是非常的强大的,...
  • vba查找sheete

    2008-12-10 11:17:00
    之前的报表全部放在一个excel文件里,所以查找sheet非常麻烦.那我就自己写了个小程序方便查找,不过没有模糊查找的功能,以后可以完善下.代码如下: Sub findName() Dim sheetFind As Worksheet Dim ...
  • Dim DicFolders As Variant Private Sub ExportFormat(format As String) Dim ArrFileName() As String, ArrLan() As String, i&amp; Dim sheetName As String, sheetActive As Variant, m&...
  • 大家好,我们今日继续讲解VBA代码解决方案的第80讲内容:如何查找文件。总是在讲解VBA,其实对于VBA来说真的功能强大,但也有他自身的不足,我的感觉,如果是处理一些数据的统计,归类VBA的作用是非常的有效的,如果...
  • VBA文件筛选

    2016-04-06 23:39:00
    在工作中,经常会碰到从一堆腐朽的source中按照一个列表去筛选出来...首先选择源目录和目标目录, 然后会从源目录中查找文件,将存在的文件自动复制的目标目录中, 不存在的文件,记录在第二列里。 Sub fileFilt...
  • 题记:春节期间,疫情施虐,大家尽可能待在家里,多学习有用的知识,多提高自己的水平和能力,这才是正道。... 195:在VBA代码中使用使用Getfile方法获取文件信息NO. 196:在VBA代码中使用使用File...
  • 目的:打开同一目录下的文件us.xls,并在第一列中查找某一指定值。在这里查找"Dev” 1,打开同一目录下的文件us.xls Dim wb As Workbook Set wb = Workbooks.Open(ThisWorkbook.Path & "/" & "us.xls", , True) wb ...
  • 这篇我们来说说如何使用VBA模糊查找当前工作表中有用的数据。我们有时会遇到这样的情况。我们手头有很多很多老的excel文件,他们都是关于提供的内容是类似的,但是他们的格式还有不同,因为表格的样式调整过,或是从...
  • 目录里面保存有面单扫描的图像文件文件名称为邮件号码。如今想收集这些邮件号码,由于量非常大,不可能一个一个的截取,仅仅能通过程序实现。假定,当前工作表B列里放的是存放这些图像文件的目录。以下的程序能够...
  • 可以判断各种情况 like = 多个条件 包含中文等等 Sub test_jackma1() path1 = ThisWorkbook.Path Dim fso As Object Dim fd1 As Object Dim f1 As Object Set fso = CreateObject("scripting....Debug....
  • 文件夹里面保存有面单扫描的图像文件文件名为邮件号码,现在想收集这些邮件号码,因为量很大,不可能一个一个的截取,只能通过程序实现,假定,当前工作表B列里放的是存放这些图像文件的文件夹,下面的程序可以讲...
  • 今天和小伙伴们分享一下,用VBA调用Word VBA的Find对象进行批量查找并替换上面Word文档,需要批量按照下面表格的查找内容进行查找,然后替换为指定的内容第3行的代码,创建一个Word应用程序对象,相当于你启用了...
  • 谢谢寻欢,原来核心就是GETOBJECT,特帖帮助内容,与大家分享:GetObject 函数示例该示例使用 GetObject 函数来获取对指定的 Microsoft Excel 的...DetectExcel Sub 过程通过调用两个 API 函数,来查找 Microsoft ...
  • Option Explicit Sub FileNames() Dim sFName As String Dim asFNames() As String Dim sFType As String ... sFName = Dir(sFType) 'Dir函数返回sFType中找到的与通配符...代码摘自<<Excel 2007 VBA 参考大全>>
  • 大家好,我们今日讲解“VBA信息获取与处理”教程中第十五个专题“将Excel数据信息传递给WORD应用”的第四节“利用字典及查找替换,将Excel信息与Word模板组合”,这个专题是非常实用的知识点,希望大家能掌握利用。...
  • 1 求助问题 ... 如果是dir 查找文件夹,需要加参数 fd1_name = Dir(ThisWorkbook.Path, vbDirectory) Sub test2() path1 = "C:\Users\Administrator\Desktop\1.xlsx" If Dir(path1) <...
  • 如何用VBA批量删除文件

    千次阅读 2018-06-09 23:36:07
    Sub 批量删除文件() mypath = ThisWorkbook.Path f = Dir(mypath &amp; "\*.xlsx") '查找当前路径下符合条件的文件名 While f &lt;&gt; "" '一直到F找不到合条件的就结束循环 ...
  • 问题:有处理学生评语,限于网络条件,往往学生提交的都是单个文件,这就需要将其一一提取出来,然后进行判断、导出等操作,但首先要解决的就是查找所有文件如何操作,这里需要用到Dir函数,当然创建一个文件搜索...
  • 破解xlsm文件VBA项目密码

    千次阅读 2018-09-27 19:19:13
    工具 待破解的xlsm文件、Excel2010、Hex Editor ...3.使用Hex软件打开vbaProject.bin文件查找DPB替换成DPx,保存文件,重新压缩,修改后缀名.zip为.xlsm 4.使用excel打开.xlsm文件,开发工具-&gt;...
  • 1 DIR基本功能 1.1Dir函数 ... 返回一个String,用以表示一个文件名、目录名或文件夹名称,它必须与指定的模式或文件属性、或磁盘卷标相匹配。 pathname 可选参数。用来指定文件名的字符串表达式,...

空空如也

空空如也

1 2 3 4 5 ... 10
收藏数 185
精华内容 74
关键字:

vba查找文件