B 获取多个Excel文件中某一单元格中内容

上传人:m**** 文档编号:464208086 上传时间:2023-11-20 格式:DOC 页数:3 大小:33KB
返回 下载 相关 举报
B 获取多个Excel文件中某一单元格中内容_第1页
第1页 / 共3页
B 获取多个Excel文件中某一单元格中内容_第2页
第2页 / 共3页
B 获取多个Excel文件中某一单元格中内容_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《B 获取多个Excel文件中某一单元格中内容》由会员分享,可在线阅读,更多相关《B 获取多个Excel文件中某一单元格中内容(3页珍藏版)》请在金锄头文库上搜索。

1、VB 获取多个Excel文件中某一单元格中内容有这样一些excel文件:甲.xls, 乙.xls, 丙.xls 想要获取每个文件sheet1中的D15单元格的数值,有什么可行的办法?例如文件 甲sheet1 中D15的值是90,则获取的结果为 甲 90 。即文件名+数值。.将下列代码粘贴到一个文本文件,并将其改名为Form1.frm,然后运行,并将工程-引用-将Microsoft Excel 12.0 Object Library选中VERSION 5.00Begin VB.Form Form1 Caption = D15 ClientHeight = 3435 ClientLeft = 60

2、 ClientTop = 450 ClientWidth = 4890 LinkTopic = Form1 ScaleHeight = 3435 ScaleWidth = 4890 StartUpPosition = 3 窗口缺省 Begin VB.TextBox Text3 Height = 375 Left = 1680 TabIndex = 6 Text = Sheet1 Top = 1080 Width = 2415 End Begin VB.TextBox Text2 Height = 375 Left = 1680 TabIndex = 4 Text = 4 Top = 600 W

3、idth = 2415 End Begin VB.TextBox Text1 Height = 375 Left = 1680 TabIndex = 3 Text = 15 Top = 120 Width = 2415 End Begin VB.CommandButton Command1 Caption = 处 理 Height = 495 Left = 2040 TabIndex = 0 Top = 2520 Width = 1215 End Begin VB.Label Label1 Caption = 要查找的表名: Height = 375 Index = 2 Left = 120

4、TabIndex = 5 Top = 1200 Width = 1335 End Begin VB.Label Label1 Caption = 要查找的列: Height = 375 Index = 1 Left = 120 TabIndex = 2 Top = 720 Width = 1095 End Begin VB.Label Label1 Caption = 要查找的行: Height = 375 Index = 0 Left = 120 TabIndex = 1 Top = 240 Width = 1095 EndEndAttribute VB_Name = Form1Attrib

5、ute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub Command1_Click()Dim I As Integer, IntTemp2 As Integer, Inttemp1 As IntegerDim StrD15 As StringDim StrTemp1 As String, StrTemp2 As String, StrTemp3 As String, StrTxtFil

6、e As StringDim S As String, tS As StringDim TxtDir() As StringStrTemp1 = Text3.TextInttemp1 = Text1.TextIntTemp2 = Text2.TextReDim TxtDir(1000) Open App.Path & D15.txt For Output As #1 Close #1tS = Dir(App.Path & *.xls, vbHidden Or vbNormal Or vbReadOnly)I = 0Do While tS TxtDir(I) = tSI = I + 1tS =

7、DirLoopReDim Preserve TxtDir(I - 1)Dim xlApp As Excel.ApplicationSet xlApp = CreateObject(Excel.Application)xlApp.Visible = FalseFor Each txtfiles In TxtDirStrTxtFile = App.Path & & txtfiles Set xlBook = xlApp.Workbooks.Open(StrTxtFile) Open App.Path & D15.txt For Append As #1 k = xlApp.Worksheets(StrTemp1).Range(A1).Cells(Inttemp1, IntTemp2) Print #1, Mid(txtfiles, 1, Len(txtfiles) - 4) & k Close #1xlApp.QuitNextSet xlApp = NothingMsgBox 已处理完成,结果保存到“ & App.Path & D15.txt”中,请查看!EndEnd Sub

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 营销创新

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号