将宏使用日志保存到 SharePoint

时间:2021-03-31 02:35:04

标签: excel vba

我是 VBA 的新手(充其量),但我正在尝试解决在有人运行宏时创建日志的问题。我已经与团队中的其他人分享了该宏,并想知道他们是否正在使用它来衡量采用情况。我已经为所有人设置了一个具有读/写访问权限的 SharePoint 文件夹,直到今天,日志一直在为我保存,但只为我保存。然后我升级到 Office 2016,它也停止为我工作。运行宏的任何人都不会收到任何错误,只是日志中没有保存任何内容。我很乐意帮助解决以下代码中可能缺少的问题。可能有更好的方法,但这对以前的团队有效....

Sub log_output(sourcedoc, evaluation_document_path, debug_option)

  logpath = "https://share.xxxxx/log.xlsx"
  Dim logdoc As Excel.Workbook
  Set objExcel1 = CreateObject("Excel.Application")
  
    On Error Resume Next
        Set logdoc = objExcel1.Workbooks.Open(FileName:=logpath, ReadOnly:=False)
                
    'check if the workbook exists
    If logdoc Is Nothing Then
      Exit Sub
    End If
    If (logdoc.ReadOnly) Then
        Exit Sub
    End If
        
  
  'the file exists so report errors as normal
  On Error GoTo 0

  objExcel1.DisplayAlerts = False
      
  objExcel1.Visible = debug_option

  Set objsheet1 = objExcel1.ActiveWorkbook.ActiveSheet
   numrows = objsheet1.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
   objsheet1.range("A" & numrows + 1) = Now
   objsheet1.range("B" & numrows + 1) = (Environ$("Username"))
   objsheet1.range("C" & numrows + 1) = sourcedoc.FullName
   objsheet1.range("D" & numrows + 1) = evaluation_document_path
   
   
    logdoc.SaveAs logdoc.FullName, AccessMode:=xlExclusive, ConflictResolution:=True
    logdoc.Close (True)
    
    
    objExcel1.DisplayAlerts = True
  
    
End Sub

0 个答案:

没有答案