网站大量收购独家精品文档,联系QQ:2885784924

使用VBA操作文件9应用示例.doc

  1. 1、本文档共7页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
使用VBA操作文件9应用示例

使用VBA操作文件(9):应用示例 2009年08月26日, 12:53 下午 ?(1?人投票, 平均:?5.00?out of 5) 下面是在vbaepress中使用VBA操控文件的一些示例代码,供参考。 选择文件并打开 不知道要打开的文件的具体位置,通过用户选择后打开该文件。 Sub GetOpenFileNameExample3() Dim lCount As Long Dim vFilename As Variant Dim sPath As String Dim lFilecount As Long sPath = c:\windows\temp\ ChDrive sPath ChDir sPath vFilename = Application.GetOpenFilename(Microsoft Excel files (*.xls),*.xls, , Please select the file(s) to open, , True) If TypeName(vFilename) = Boolean Then Exit Sub For lCount = 1 To UBound(vFilename) Workbooks.Open vFilename(lCount) Next End Sub 如果要选择打开图片文件,则将文件类型改为: Image files (*.jpg),*.jpg 搜索文件 搜索指定目录中含有关键词的所有文件并打开这些文件。 Sub OpenBooksInFolder() ? Dim FileFound As String, N As Long Dim Sheet As Worksheet, FilePath As String ? stipulate the folders path here FilePath = C:\Documents and Settings\m\桌面 ? DoEvents Application.ScreenUpdating = False ? list all the books in the folder With Application.FileSearch .LookIn = FilePath .FileType = msoFileTypeExcelWorkbooks ? this should gives partial matches i.e. anything with happy in the name regardless of case .Filename = 水工 ? false = only search given folder .SearchSubFolders = False ? On Error Resume Next If .Execute 0 Then For N = 1 To .FoundFiles.Count ? Debug.Print .FoundFiles(N) make a choice Workbooks.Open (.FoundFiles(N)) make a choice now do what you want to do with each open workbook Next N Else MsgBox The file .Filename was not found End If End With Application.ScreenUpdating = True End Sub 基于文件名将文件移到相应的文件夹中 有许多文件,现在希望根据文件名将该文件移至相应的文件夹。例如,将名称中包含“Bankhill”的文件移到“Bankhill”文件夹,名称中包含“Lite”的文件移到“Lite”文件夹,等等。 Sub LoopFolder() Const SourceFolder As String = C:\Users\ianlane

文档评论(0)

173****7830 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档