第十二回 同是藏身文件夹,相逢何必问姓名.xlsm - sub readTxt dim s as string i as long open"d\demo 客户�息 for input as#1 i=1 do

第十二回 同是藏身文件夹,相逢何必问姓名.xlsm

This preview shows page 1 - 9 out of 9 pages.

sub readTxt() dim s as string, i as long open"d:\demo\ 客户信息 .txt" for input as #1 ' 每打开一个文件时,必须 i=1 do while not EOF(1) Line input #1,s 同时打开两个文本文件,将内容交错记录在新的 excel 表格中 sub readTxt2() dim i as long, j as long ,s as string open"d:\demo\ 残本 1.txt" for input as #1 open"d:\demo\ 残本 2.txt" for input as #2 i =2 do while not EOF(1) or not EOF(2) if not EOF(1) then Line input #1,s cells(i,2)=s : i=i+1 end if if not EOF(2) then Line input #2,s cells(i,2)=s : i=i+1 end if Loop Close#1: close#2 open "d:\demo\ 葵花宝典 .txt" for output as #3‘ 也可以是 #1 ,因为 #1 i=2 do while cells(i,2) <>"" print #3, cells(i,2) i=i+1 Loop Close#3 end sub 一个目录下所有文件的名字 DIR 函数 sub dirtest() dim f as string f=dir("d:\demo2\") ' 以反斜杠 \” 结尾代表文件夹,否则会被当作一 msgbox f end sub 读取一个文件夹下所有文件的名字 sub dirdemo() dim f as string f=dir("d:\demo2\")
Image of page 1

Subscribe to view the full document.

Image of page 2
Image of page 3

Subscribe to view the full document.

Image of page 4
Image of page 5

Subscribe to view the full document.

Image of page 6
Image of page 7

Subscribe to view the full document.

Image of page 8
Image of page 9

Unformatted text preview: do while f &lt; &gt;&quot;&quot; ' 在此处对名为 f 的文件进行打开和读取操作 f=dir Loop Loop end sub sub dirdemo() dim f as string f=dir(&quot;d:\demo2\&quot;) do while f &lt;&gt; &quot;&quot; call readformfile(&quot;d:\demo2\&quot;&amp;f) f=Dir Loop end sub sub readformfile(full name as string) dim ws as worksheet, i as long , s as string ' 创建新工作表,并将表名改为文件名, instrRev 函数与 instr 函数功能相同 set ws=worksheets.add ws.name=mid(fullname,instrRev(fullname,&quot;\&quot;)+1) open fullName for input as #1 i=1 Do while Not EOF ( 1 ) Line input#1,s ws.cells(i,2)=Left(s,2) ws.cells(i,3)=Mid(s,instr(s,&quot; 电话 &quot;)+3, 8) i=i+1 Loop Close#1 end sub 须给他指定唯一的一个数字编号 在之前已经被关闭,所以命名新的文件编号为 #1 不会冲突 一个文件,即 D “ 盘下名为 demo2 ” 的文件 同,不过是从最右边开始查找字符...
View Full Document

  • Spring '11
  • Lee

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask bonus questions You can ask questions ( expire soon) You can ask questions (will expire )
Answers in as fast as 15 minutes