码迷,mamicode.com
首页 > 编程语言 > 详细

VBA点滴备忘录(持续更新中)

时间:2014-11-05 14:43:55      阅读:316      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   for   sp   文件   div   on   

1、判断Excel文件是否已打开以及自动打开文件
Function openWorkbook(ByVal fileName, ByVal filePath)
    On Error Resume Next
    If Len(Workbooks(fileName).Name) <= 0 Then
        Workbooks.Open (filePath)
    End If
End Function

  

2、从文件全路径中截取文件名

Dim FilePath As String
FilePath = "C:\xxx\xxxx\review.txt"
Dim FileName As String
FileName = Right(FilePath, Len(FilePath) - InStrRev(FilePath, "\"))

  

3、从文件全路径名中截取文件夹路径

Dim filePath As String
filePath = "C:\xxx\xxxx\review.txt"
Dim forlderPath As String
forlderPath = Left(filePath, InStrRev(filePath, "\"))

 

4、统计某个文件夹下的文件个数

Function getFileCount(ByVal forlderPath, ByVal filePath, index)
    Dim tmpFilePath As String
    tmpFilePath = Dir(forlderPath & "*.*")
    Dim i As Integer
    i = 0
    Do While tmpFilePath <> ""
        i = i + 1
        If tmpFilePath = filePath Then
            index = i
        End If
        tmpFilePath = Dir
    Loop
    getFileCount = i
End Function

  

5、获取文件的最近修改的日期与时间

FileDateTime("filePah")

 

6、判断某一地址单元格是否为合并单元格,如果是,则其为几列几行合并而成

Sub myMerge()
    Set cel = Range("A1")
    If cel.MergeCells Then
        MsgBox cel.Address(0, 0) & "为合并单元格," & "共有" & cel.MergeArea.Rows.Count & "行" & cel.MergeArea.Columns.Count & "列组成"
    End If
End Sub

 

VBA点滴备忘录(持续更新中)

标签:style   blog   io   ar   for   sp   文件   div   on   

原文地址:http://www.cnblogs.com/kzby2003/p/4076167.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!