vba获取excel文件本身的版本|excel vba打开excel文件

vba获取excel文件本身的版本|excel vba打开excel文件的第1张示图

㈠ VBA中用什么方法可以得到EXCEL文件中工作表数量

插入模块运行

Sub JS()

Dim i As Integer

i = Worksheets.Count

MsgBox "工作表数量是" & i

End Sub

Visual Basic for Applications(VBA)是Visual Basic的一种宏语言,是微软开发出来在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。主要能用来扩展Windows的应用程序功能,特别是Microsoft Office软件。也可说是一种应用程式视觉化的Basic 脚本。该语言于1993年由微软公司开发的的应用程序共享一种通用的自动化语言——–Visual Basic For Application(VBA),实际上VBA是寄生于VB应用程序的版本。微软在1994年发行的Excel5.0版本中,即具备了VBA的宏功能。

㈡ 怎么用Excel的VBA获取本文件的属性,查看本文件有多大

你好,代码如下:

第一句获取文件大小

第二句填充“A1”单元格

Submain()iSize=Format(FileLen(ActiveWorkbook.FullName)/1048576,"0.00")Range("A1").Value=iSize&"MB"EndSub

㈢ vba excel 不同文件文件查询

1.单元格的值作为文件名称,你可能用& 连接符,如:("=LOOKUP(1,0/([ " & cells(I,1) &"2.Wk.Close False只是关闭当然保存不了,用个save吧.3.调用d盘下da.xls,是无法直接用语句简易引用的,有两种方法,一种是打开那个表,另一个方法是不打开那个表,设置公式引用表中数据然后再处理4.引用当前单元格L1的值,方法同1.

㈣ 关于用vba把excel中的数据保存到一个csv文件中。

不能保存,你又说不出提示什么错误,没办法。

阴影是什么样的?截图看看?或者把表发我邮箱。

保存可以用下面代码

Application.DisplayAlerts = False ActiveSheet.SaveAs “c:aaaaa”, xlCSV Application.DisplayAlerts = Trueqq邮箱 [email protected]

㈤ VBA如何获取当前EXCEL文件的路径

1、首先打来开Excel数据表,在开发自工具中打开VBA编辑器。

㈥ excel vba打开excel文件

不知道这样符不符合你的要求(一个打开,一个恢复显示回):Sub 后台打开答() Application.ScreenUpdating = False Workbooks.Open Filename:="D:\excel.xls" ActiveWindow.Visible = False Application.ScreenUpdating = TrueEnd SubSub 取消隐藏() Windows("excel.xls").Visible = TrueEnd Sub

㈦ 如何用VBA 读取excel所有数据

通过VBA中的函数sheets(!workbook.worksheet).select,就可以将当前的文件指针指向所选的工作薄中的指定工作表。参数说明:workbook为工作簿名即文件名worksheet为工作表名当文件指针设定好后,就可以对指定文件的指定工作表进行操作了。

㈧ VBA 如何取C盘下和C盘文件夹下所有Excel文件名称,并将这些文件名放到Excel文件上。

VBA遍历文件夹常用有三种方法,这三种方法中,filesearch不适合2007和2010版本,而且速度比较慢,递归法速度也慢。只有用DIR加循环的方法,速度飞快。下面是三种方法的代码: 1、filesearch法Sub test3()Dim wb As WorkbookDim i As LongDim tt = Timer With Application.FileSearch '调用fileserch对象 .NewSearch '开始新的搜索 .LookIn = ThisWorkbook.path '设置搜索的路径 .SearchSubFolders = True '搜索范围包括 LookIn 属性指定的文件夹中的所有子文件夹 .Filename = "*.xls" '设置搜索的文件类型 ' .FileType = msoFileTypeExcelWorkbooks If .Execute() > 0 Then '如果找到文件 For i = 1 To .FoundFiles.Count 'On Error Resume Next Cells(i, 1) = .FoundFiles(i) '把找到的文件放在单元格里 Next i Else MsgBox "没找到文件" End If End With MsgBox Timer – tEnd Sub 2、递归法 Sub Test()Dim iPath As String, i As LongDim tt = Timer With Application.FileDialog(msoFileDialogFolderPicker) .Title = "请选择要查找的文件夹" If .Show Then iPath = .SelectedItems(1) End If End With If iPath = "False" Or Len(iPath) = 0 Then Exit Sub i = 1 Call GetFolderFile(iPath, i) MsgBox Timer – t MsgBox "文件名链接获取完毕。", vbOKOnly, "提示" End SubPrivate Sub GetFolderFile(ByVal nPath As String, ByRef iCount As Long)Dim iFileSys'Dim iFile As Files, gFile As File'Dim iFolder As Folder, sFolder As Folders, nFolder As Folder Set iFileSys = CreateObject("Scripting.FileSystemObject") Set iFolder = iFileSys.GetFolder(nPath) Set sFolder = iFolder.SubFolders Set iFile = iFolder.Files With ActiveSheet For Each gFile In iFile ' .Hyperlinks.Add anchor:=.Cells(iCount, 1), Address:=gFile.path, TextToDisplay:=gFile.Name iCount = iCount + 1 Next End With '递归遍历所有子文件夹 For Each nFolder In sFolder Call GetFolderFile(nFolder.path, iCount) NextEnd Sub 3、dir循环法Sub Test() '使用双字典,旨在提高速度 Dim MyName, Dic, Did, i, t, F, TT, MyFileName 'On Error Resume Next Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.BrowseForFolder(0, "选择文件夹", 0, 0) If Not objFolder Is Nothing Then lj = objFolder.self.path & "\" Set objFolder = Nothing Set objShell = Nothing t = Time Set Dic = CreateObject("Scripting.Dictionary") '创建一个字典对象 Set Did = CreateObject("Scripting.Dictionary") Dic.Add (lj), "" i = 0 Do While i < Dic.Count Ke = Dic.keys '开始遍历字典 MyName = Dir(Ke(i), vbDirectory) '查找目录 Do While MyName <> "" If MyName <> "." And MyName <> ".." Then If (GetAttr(Ke(i) & MyName) And vbDirectory) = vbDirectory Then '如果是次级目录 Dic.Add (Ke(i) & MyName & "\"), "" '就往字典中添加这个次级目录名作为一个条目 End If End If MyName = Dir '继续遍历寻找 Loop i = i + 1 Loop Did.Add ("文件清单"), "" '以查找D盘下所有EXCEL文件为例 For Each Ke In Dic.keys MyFileName = Dir(Ke & "*.xls") Do While MyFileName <> "" Did.Add (Ke & MyFileName), "" MyFileName = Dir Loop Next For Each Sh In ThisWorkbook.Worksheets If Sh.Name = "XLS文件清单" Then Sheets("XLS文件清单").Cells.Delete F = True Exit For Else F = False End If Next If Not F Then Sheets.Add.Name = "XLS文件清单" End If Sheets("XLS文件清单").[A1].Resize(Did.Count, 1) = WorksheetFunction.Transpose(Did.keys) TT = Time – t MsgBox Minute(TT) & "分" & Second(TT) & "秒"End Sub

㈨ vba读取excel文件数据

程序代编,欢迎联络。

㈩ vba获取本机excel的版本名

Sub ExcelVersion()verarr = Array("8.0", "9.0", "10.0", "11.0", "12.0", "14.0")vername = Array("97", "2000", "2002", "2003", "2007", "2010")For i = 1 To 6If verarr(i – 1) = Application.Version ThenMsgBox "当前Excel版本为:Excel " & vername(i – 1)Exit ForEnd IfNext iEnd Sub

未经允许不得转载:山九号 » vba获取excel文件本身的版本|excel vba打开excel文件

赞 (0)