excel 我如何将此VBA代码集成到我公司的onedrive/teams云数据库中以每天保存[关闭]

7fhtutme  于 2023-06-25  发布在  其他
关注(0)|答案(1)|浏览(97)

**关闭。**此题需要debugging details。目前不接受答复。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答这个问题。
昨天关门了。
Improve this question
此代码旨在收集机器的扭矩数据,并根据当天收到的数据创建文件。然后,它将其保存在云中,以便稍后在需要时进行审查。

Public Sub UploadDataToFile()
    Dim currentDate As Date
    Dim lastRow As Long
    Dim i As Long
    Dim filePath As String
    Dim fileName As String
   
    'Get today's date
    currentDate = Date
   
    'Get the last row of data in column B
    lastRow = Cells(Rows.Count, "B").End(xlUp).Row
   
    'Loop through each row in the data range
    For i = lastRow To 2 Step -1
        If Cells(i, "B").Value < currentDate Then
            'If the date in column B is less than today's date, delete the entire row
            Rows(i).Delete
        End If
    Next i
   
    'Set the file name based on current date
    fileName = Format(currentDate, "yyyy-mm-dd") & "TorqueValues.xlsx"
   
    'Set the file path for saving in OneDrive for Business
    filePath = "C:\Users\Austin Manufacturing Engineering\OneDrive - ThermoFisher\" & fileName
   
    'Copy the data to a new workbook
    Dim newWorkbook As Workbook
    Set newWorkbook = Workbooks.Add
   
    ThisWorkbook.ActiveSheet.Copy Before:=newWorkbook.Sheets(1)
   
    'Save the new workbook at the specified file path with file format
    newWorkbook.SaveAs fileName:=filePath, FileFormat:=51
   
    newWorkbook.Close SaveChanges:=False
End Sub

我在“newWorkbook.SaveAs fileName:=filePath,FileFormat:=51”得到一个错误,它说运行时错误1004,VB项目和XLM电子表格不能保存在无宏工作簿中。现在,我已经有了代码的主要构建块,但我似乎不知道如何使用正确的文件路径集成到我们的系统中。当我运行代码时,我总是出错。

e0bqpujr

e0bqpujr1#

这不是错误,而是警告。您可以关闭它:

Application.DisplayAlerts = False
newWorkbook.SaveAs fileName:=filePath, FileFormat:=51
Application.DisplayAlerts = True

相关问题