|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Public Function GetValueByKey(strKey As String, iOffsetValue As Long) As String
- Dim mySheet As Worksheet
- Set mySheet = ThisWorkbook.Worksheets("ConfigSheet")
- GetValueByKey = mySheet.UsedRange.Find(strKey, Lookat:=xlWhole).Offset(0, iOffsetValue).Value
- End Function
复制代码 Public Function GetExcelWorkSheetName(ByVal strFileFullPath As String) As Variant()
'/ ADOX
' Dim cat As New ADOX.Catalog
Dim cat As Object
Dim myTable As Object
Dim iLoop As Long
Dim arr()
Dim sNewSheetName As String
Set cat = CreateObject("ADOX.catalog")
cat.ActiveConnection = "Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & strFileFullPath
For Each myTable In cat.Tables
If myTable.Type = "TABLE" Then
sNewSheetName = VBA.Replace(myTable.Name, "'", "")
If VBA.right(sNewSheetName, 1) = "$" Then
iLoop = iLoop + 1
ReDim Preserve arr(1 To iLoop)
arr(iLoop) = sNewSheetName
End If
End If
Next
GetExcelWorkSheetName = arr
Set cat = Nothing
End Function
- Public Sub ShowMsgbox(ByVal sMsgContent As String, ByVal iMsgType As Integer)
- Select Case iMsgType
- '/ Information
- Case 1
- MsgBox sMsgContent, vbInformation + vbOKOnly, "Information"
- '/ Warning
- Case 2
- MsgBox sMsgContent, vbExclamation + vbOKOnly, "Warning"
- End Select
- End Sub
复制代码 Public Function TimeDiff(dteStart As Date, dteEnd As Date) As String
Dim lngDiff As Long
Dim i As Integer
Dim strCheck(3)
lngDiff = DateDiff("s", dteStart, dteEnd)
strCheck(0) = CStr(lngDiff Mod 60) & "s"
strCheck(1) = CStr(lngDiff \ 60 Mod 60) & "m"
strCheck(2) = CStr(lngDiff \ 60 \ 60 Mod 24) & "h"
strCheck(3) = CStr(lngDiff \ 60 \ 60 \ 24) & "d"
For i = 0 To 3
If left(strCheck(i), 1) = "0" Then
strCheck(i) = ""
End If
Next
TimeDiff = strCheck(3) & strCheck(2) & strCheck(1) & strCheck(0)
End Function
- Public Function GetFileExtenName(ByVal strFileFullPath As String) As String
- Dim sFileName As String
- Dim fso As Object
- Set fso = CreateObject("Scripting.FileSystemObject")
- sFileName = "." & fso.GetExtensionName(strFileFullPath)
- If Trim(sFileName) <> "" Then
- GetFileExtenName = sFileName
- End If
- Set fso = Nothing
- End Function
- Public Sub EmptyFolderFiles(ByVal strFolderPath As String)
- Dim fso As Object
- Dim EachFile As Object
- Dim oFolder As Object
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set oFolder = fso.GetFolder(strFolderPath)
- For Each EachFile In oFolder.Files
- EachFile.Delete
- Next
- Set fso = Nothing
- Set oFolder = Nothing
- End Sub
- Public Function CheckFolderFileEmpty(ByVal strFolderPath As String) As Boolean
- Dim fso As Object
- Dim oFolder As Object
- Dim oFiles As Object
- Dim oFile As Object
- 'Dim fso As New FileSystemObject
- 'Dim oFolder As Folder
- 'Dim oFile As File
- CheckFolderFileEmpty = False
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set oFolder = fso.GetFolder(strFolderPath & "")
- If oFolder.Files.Count = 0 Then
- CheckFolderFileEmpty = True
- Else
- For Each oFile In oFolder.Files
- If VBA.left(fso.GetExtensionName(oFile.Name), 3) <> "xls" Then
- Call ShowMsgbox("[ " & oFile.Name & " ] is NOT Excel File Format,Please Check it.", 2)
- CheckFolderFileEmpty = True
- Exit Function
- End If
- Next
- End If
- Set fso = Nothing
- Set oFolder = Nothing
- Set oFile = Nothing
- End Function
复制代码 Public Function GetFilesName(ByVal FileFolderPath As String)
Dim objFileSysObj As Object
Dim objFolder As Object
Dim objFiles As Object
Dim objFile As Object
Dim sFiles() As String
Dim iCount As Long
Dim k As Long
Set objFileSysObj = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFileSysObj.GetFolder(FileFolderPath)
Set objFiles = objFolder.Files
iCount = objFiles.Count
If iCount = 0 Then
MsgBox " No File Existed in Input Folder."
Exit Function
End If
ReDim sFiles(iCount - 1)
For Each objFile In objFiles
If left((objFile.Name), 1) <> "~" Then
If left(GetFileExtenName(objFile.Name), 4) = ".xls" Then
sFiles(k) = objFile.Name
k = k + 1
End If
End If
Next
GetFilesName = sFiles()
End Function
Public Function CheckFolderPathExists(ByVal strFolderFullPath As String)
Dim fso As Object
'Dim fso As New FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(strFolderFullPath) = False Then
fso.CreateFolder (strFolderFullPath)
End If
End Function
|
|