VBA Access/Excel - 创建日志文件
VBA Access/Excel - Create log file
在 MS Access 中是否可以创建仅显示修改后的工作簿的日志文件(或 txt 文件)
以下代码编辑多个 excel 工作簿,但在编辑工作簿之前,它首先检查工作簿是否处于 read/write 模式。如果不是,那么它将关闭并打开工作簿,直到 read/write 处于活动状态。
For Each i In MyArray
xl.Workbooks.Open (i)
'If workbook in read only mode , close and open till read/write is active
Do Until xl.ActiveWorkbook.ReadOnly = False
xl.ActiveWorkbook.Close (False)
If GetAttr(i) = vbReadOnly Then _
SetAttr i, vbNormal
xl.Workbooks.Open (i)
If xl.ActiveWorkbook.ReadOnly = False Then Exit Do
Loop 'Loop above till read/write active
'''''More code here when workbook read/write mode
Next
我假设您想创建一个日志文件并写下您设法为 R/W 打开的每个 Excel 工作簿的名称。这是使用后期绑定的解决方案:
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.CreateTextFile("c:\myLogFile.txt")
For Each i In MyArray
xl.Workbooks.Open (i)
Do Until xl.ActiveWorkbook.ReadOnly = False
xl.ActiveWorkbook.Close (False)
If GetAttr(i) = vbReadOnly Then SetAttr i, vbNormal
xl.Workbooks.Open (i)
If xl.ActiveWorkbook.ReadOnly = False Then
ts.WriteLine "opened file: " & xl.ActiveWorkbook.Name
Exit Do
End If
Loop 'Loop above till read/write active
'''''More code here when workbook read/write mode
Next
在 MS Access 中是否可以创建仅显示修改后的工作簿的日志文件(或 txt 文件)
以下代码编辑多个 excel 工作簿,但在编辑工作簿之前,它首先检查工作簿是否处于 read/write 模式。如果不是,那么它将关闭并打开工作簿,直到 read/write 处于活动状态。
For Each i In MyArray
xl.Workbooks.Open (i)
'If workbook in read only mode , close and open till read/write is active
Do Until xl.ActiveWorkbook.ReadOnly = False
xl.ActiveWorkbook.Close (False)
If GetAttr(i) = vbReadOnly Then _
SetAttr i, vbNormal
xl.Workbooks.Open (i)
If xl.ActiveWorkbook.ReadOnly = False Then Exit Do
Loop 'Loop above till read/write active
'''''More code here when workbook read/write mode
Next
我假设您想创建一个日志文件并写下您设法为 R/W 打开的每个 Excel 工作簿的名称。这是使用后期绑定的解决方案:
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.CreateTextFile("c:\myLogFile.txt")
For Each i In MyArray
xl.Workbooks.Open (i)
Do Until xl.ActiveWorkbook.ReadOnly = False
xl.ActiveWorkbook.Close (False)
If GetAttr(i) = vbReadOnly Then SetAttr i, vbNormal
xl.Workbooks.Open (i)
If xl.ActiveWorkbook.ReadOnly = False Then
ts.WriteLine "opened file: " & xl.ActiveWorkbook.Name
Exit Do
End If
Loop 'Loop above till read/write active
'''''More code here when workbook read/write mode
Next