VBA比较常用共通方法(一)写文本文件续

本文介绍了一个使用VB.NET创建目录的函数,该函数通过检查路径并递归地创建所有必要的子目录来实现目录创建。
Public Function NewDir(ByVal strPath) As Boolean
    
    Dim dirAttr As VbFileAttribute
    
    dirAttr = vbNormal + vbDirectory + vbReadOnly
    If Dir(strPath, dirAttr) <> "" Then
        NewDir = True
        Exit Function
    End If
    
    Dim Pos As Long
    Dim strTemp As String
    
    On Error Resume Next
    Pos = InStr(1, strPath, "\")
    While Pos > 0
        strTemp = Left(strPath, Pos - 1)
        If Dir(strTemp, dirAttr) = "" Then MkDir strTemp
        Pos = InStr(Pos + 1, strPath, "\")
    Wend
    
    MkDir strPath
    
    NewDir = (Dir(strPath, dirAttr) <> "")
    If Err <> 0 Then Err.Clear
    
End Function

Public Sub SysErr(ByVal s As String)
    If IsAutoRun Then Exit Sub
    LimitMsgBoxText s
    MsgBox s, vbCritical, "错误提示"
End Sub

Private Sub LimitMsgBoxText(s As String)
    Const nMaxLen As Integer = 250
    If Len(s) > nMaxLen Then s = Left(s, nMaxLen) & "..."
End Sub

Public Sub KillFile(strFile As String)
    
    If Dir(strFile, vbHidden + vbNormal + vbReadOnly) <> "" Then
        SetAttr strFile, vbNormal
        Kill strFile
    End If
    
End Sub
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值