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

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

 

转载于:https://www.cnblogs.com/kzby2003/p/4076167.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值