用VBA编程如何修改bartender文件的文件名
发布网友
发布时间:2022-05-19 16:18
我来回答
共2个回答
热心网友
时间:2023-10-14 16:38
Sub 批量改名()
Dim FolderName As String, wbName As String, cValue As Variant
Dim wbList() As String, wbCount As Integer, i As Integer, str As String, exname As String
FolderName = "G:\360data\重要数据\桌面\新建文件夹" '文件夹路径
'创建文件夹中工作簿列表
wbCount = 0
wbName = Dir(FolderName & "\" & "*.xls*")
While wbName <> ""
wbCount = wbCount + 1
ReDim Preserve wbList(1 To wbCount)
wbList(wbCount) = wbName
wbName = Dir
Wend
If wbCount = 0 Then Exit Sub
'从每个工作簿中获取数据
For i = 1 To wbCount
cValue = GetInfoFromClosedFile(FolderName, wbList(i), "sheet1", "a1")
exname = Mid(wbList(i), InStr(wbList(i), "."))
Name FolderName & "\" & wbList(i) As FolderName & "\" & cValue & exname
On Error Resume Next
Name FolderName & "\" & wbList(i) As FolderName & "\" & cValue & i & exname
Next i
End Sub
'====================从未打开表中获取信息===========================
Private Function GetInfoFromClosedFile(ByVal wbPath As String, _
wbName As String, wsName As String, cellRef As String) As Variant
Dim arg As String
GetInfoFromClosedFile = ""
If Right(wbPath, 1) <> "\" Then wbPath = wbPath & "\"
If Dir(wbPath & "\" & wbName) = "" Then Exit Function
arg = "'" & wbPath & "[" & wbName & "]" & _
wsName & "'!" & Range(cellRef).Address(True, True, xlR1C1)
r = 0
On Error Resume Next
GetInfoFromClosedFile = ExecuteExcel4Macro(arg)
End Function
热心网友
时间:2023-10-14 16:39
调用system函数。