Vba 四天后清除图纸值的宏
我需要您的帮助,在Excel文件中创建宏,从今天的日期(即“2015年6月2日”)起四天后清除工作表(称为“Sheet1”)中的所有值,并保存它。因此,一旦用户在第五天打开Excel文件,工作表将是空白的 清除数据的代码为:Vba 四天后清除图纸值的宏,vba,excel,Vba,Excel,我需要您的帮助,在Excel文件中创建宏,从今天的日期(即“2015年6月2日”)起四天后清除工作表(称为“Sheet1”)中的所有值,并保存它。因此,一旦用户在第五天打开Excel文件,工作表将是空白的 清除数据的代码为: Sheet1.Cells.Clear 但我的问题是如何在四天后清除数据,并在用户在第五天看不到任何数据的情况下保存更改。这对您很有用DateDiff是一个很好的函数,它可以返回两个日期之间的差值(年、月、日、小时……),还可以使用FileDateTime获取文件的日期 S
Sheet1.Cells.Clear
但我的问题是如何在四天后清除数据,并在用户在第五天看不到任何数据的情况下保存更改。这对您很有用
DateDiff
是一个很好的函数,它可以返回两个日期之间的差值(年、月、日、小时……),还可以使用FileDateTime
获取文件的日期
Sub Workbook_Open()
If DateDiff("d", FileDateTime(ThisWorkbook.FullName), Now) >= 4 Then
Sheet1.Cells.Clear
ThisWorkbook.Save
End If
End Sub
这对你有用
DateDiff
是一个很好的函数,它可以返回两个日期之间的差值(年、月、日、小时……),还可以使用FileDateTime
获取文件的日期
Sub Workbook_Open()
If DateDiff("d", FileDateTime(ThisWorkbook.FullName), Now) >= 4 Then
Sheet1.Cells.Clear
ThisWorkbook.Save
End If
End Sub
我还没有机会测试它,但我可以建议如下:
Private Sub Workbook_Open()
Dim currDate As String, closeDate As String, fileDate As String
Dim oFS As Object, sFile As String
currDate = Date
closeDate = Date(Year(currDate); Month(currDate); Day(currDate)-4)
sFile = Application.ActiveWorkbook.Fullname
Set oFS = CreateObject("Scripting.FileSystemObject")
fileDate = oFS.GetFile(sFile).Datelastmodified
If fileDate <= closeDate Then
' Change argument passed to Sheets to whatever sheet you want to kill off
ActiveWorkbook.Sheets(1)Cells.Clear
End If
End Sub
Private子工作簿\u Open()
Dim currDate为字符串,closeDate为字符串,fileDate为字符串
Dim oFS作为对象,sFile作为字符串
currDate=日期
closeDate=日期(年(当前日期);月(当前日期);日(当前日期)-4)
sFile=Application.ActiveWorkbook.Fullname
Set of s=CreateObject(“Scripting.FileSystemObject”)
fileDate=oFS.GetFile(sFile).Datelastmodified
如果fileDate我还没有机会测试它,但我是否可以建议这样做:
Private Sub Workbook_Open()
Dim currDate As String, closeDate As String, fileDate As String
Dim oFS As Object, sFile As String
currDate = Date
closeDate = Date(Year(currDate); Month(currDate); Day(currDate)-4)
sFile = Application.ActiveWorkbook.Fullname
Set oFS = CreateObject("Scripting.FileSystemObject")
fileDate = oFS.GetFile(sFile).Datelastmodified
If fileDate <= closeDate Then
' Change argument passed to Sheets to whatever sheet you want to kill off
ActiveWorkbook.Sheets(1)Cells.Clear
End If
End Sub
Private子工作簿\u Open()
Dim currDate为字符串,closeDate为字符串,fileDate为字符串
Dim oFS作为对象,sFile作为字符串
currDate=日期
closeDate=日期(年(当前日期);月(当前日期);日(当前日期)-4)
sFile=Application.ActiveWorkbook.Fullname
Set of s=CreateObject(“Scripting.FileSystemObject”)
fileDate=oFS.GetFile(sFile).Datelastmodified
如果fileDate有时间戳?否仅在4天后有时间戳?否仅在4天后有时间戳?否仅在4天后有时间戳宏将自动运行,或者是否有类似于每次打开excel文件时运行的onload的函数?此宏将在每次打开工作簿时运行宏运行自动运行或是否有类似于onload的函数将在每次打开excel文件时运行?此宏将在每次打开工作簿时运行宏将自动运行或是否有类似于onload的函数将在每次打开excel文件时运行?此宏将在每次打开工作簿时运行