我需要做的是在按钮上单击打开另一个工作簿,从中运行宏,然后从打开的工作簿中的特定单元格中复制信息,然后将这些值粘贴到当前工作簿的单元格中。让其他工作簿打开并运行的宏很顺利,但问题是我需要根据时间将复制的信息粘贴到特定的单元格中。我已经得到了以下代码,我认为应该根据时间选择单元格,但它实际上并没有粘贴任何内容。请让我知道我错过了什么或我做错了什么!'
Sub Update()
Dim sht As Worksheet
Dim lastRow As Long
lastRow = ActiveSheet.UsedRange.Rows.Count
Set sht = ThisWorkbook.Worksheets("Sheet1")
Dim path As String
path = "C:\Users\Redacted\Desktop\Booking Window Avai -working copy.xlsm"
Dim currentWb As Workbook
Set currentWb = ThisWorkbook
Dim openWb As Workbook
Set openWb = Workbooks.Open(path)
Dim openWs As Worksheet
Set openWs = openWb.Sheets("Mail Format")
Dim rng_data As Range
'Application.Run ("'R:\Command Center\Primary Tools\Booking Window Avail-Open Tracking - Updated 20170928.xlsm'!refreshpivot")
Application.Run ("'C:\Users\jredacted\Desktop\Booking Window Avai -working copy.xlsm'!refreshpivot")
Set rng_data = openWs.Range("B17")
If ("C2") = "" And Now() > ("09:00") And Now() < ("10:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("C2").PasteSpecial xlPasteValues]
ElseIf ("C3") = "" And Now() > ("10:00") And Now() < ("11:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("C3").PasteSpecial xlPasteValues]
ElseIf ("C4") = "" And Now() > ("11:00") And Now() < ("12:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("C4").PasteSpecial xlPasteValues]
ElseIf ("C5") = "" And Now() > ("12:00") And Now() < ("13:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("C5").PasteSpecial xlPasteValues]
ElseIf ("C6") = "" And Now() > ("13:00") And Now() < ("14:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("C6").PasteSpecial xlPasteValues]
ElseIf ("C7") = "" And Now() > ("14:00") And Now() < ("15:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("C7").PasteSpecial xlPasteValues]
ElseIf ("C8") = "" And Now() > ("15:00") And Now() < ("16:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("C8").PasteSpecial xlPasteValues]
ElseIf ("C9") = "" And Now() > ("16:00") And Now() < ("17:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("C9").PasteSpecial xlPasteValues]
End If
Set rng_data = openWs.Range("C17")
If ("D2") = "" And Now() > ("09:00") And Now() < ("10:00") Then
rng_data.Copy
[currentWb.Sheets("sht").Range("D2").PasteSpecial xlPasteValues]
ElseIf ("D3") = "" And Now() > ("10:00") And Now() < ("11:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("D3").PasteSpecial xlPasteValues]
ElseIf ("D4") = "" And Now() > ("11:00") And Now() < ("12:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("D4").PasteSpecial xlPasteValues]
ElseIf ("D5") = "" And Now() > ("12:00") And Now() < ("13:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("D5").PasteSpecial xlPasteValues]
ElseIf ("D6") = "" And Now() > ("13:00") And Now() < ("14:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("D6").PasteSpecial xlPasteValues]
ElseIf ("D7") = "" And Now() > ("14:00") And Now() < ("15:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("D7").PasteSpecial xlPasteValues]
ElseIf ("D8") = "" And Now() > ("15:00") And Now() < ("16:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("D8").PasteSpecial xlPasteValues]
ElseIf ("D9") = "" And Now() > ("16:00") And Now() < ("17:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("D9").PasteSpecial xlPasteValues]
End If
Set rng_data = openWs.Range("E26")
If ("E2") = "" And Now() > ("09:00") And Now() < ("10:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("E2").PasteSpecial xlPasteValues]
ElseIf ("E3") = "" And Now() > ("10:00") And Now() < ("11:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("E3").PasteSpecial xlPasteValues]
ElseIf ("E4") = "" And Now() > ("11:00") And Now() < ("12:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("E4").PasteSpecial xlPasteValues]
ElseIf ("E5") = "" And Now() > ("12:00") And Now() < ("13:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("E5").PasteSpecial xlPasteValues]
ElseIf ("E6") = "" And Now() > ("13:00") And Now() < ("14:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("E6").PasteSpecial xlPasteValues]
ElseIf ("E7") = "" And Now() > ("14:00") And Now() < ("15:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("E7").PasteSpecial xlPasteValues]
ElseIf ("E8") = "" And Now() > ("15:00") And Now() < ("16:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("E8").PasteSpecial xlPasteValues]
ElseIf ("E9") = "" And Now() > ("16:00") And Now() < ("17:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("E9").PasteSpecial xlPasteValues]
End If
Set rng_data = openWs.Range("E29")
If ("F2") = "" And Now() > ("09:00") And Now() < ("10:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("F2").PasteSpecial xlPasteValues]
ElseIf ("F3") = "" And Now() > ("10:00") And Now() < ("11:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("F3").PasteSpecial xlPasteValues]
ElseIf ("F4") = "" And Now() > ("11:00") And Now() < ("12:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("F4").PasteSpecial xlPasteValues]
ElseIf ("F5") = "" And Now() > ("12:00") And Now() < ("13:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("F5").PasteSpecial xlPasteValues]
ElseIf ("F6") = "" And Now() > ("13:00") And Now() < ("14:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("F6").PasteSpecial xlPasteValues]
ElseIf ("F7") = "" And Now() > ("14:00") And Now() < ("15:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("F7").PasteSpecial xlPasteValues]
ElseIf ("F8") = "" And Now() > ("15:00") And Now() < ("16:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("F8").PasteSpecial xlPasteValues]
ElseIf ("F9") = "" And Now() > ("16:00") And Now() < ("17:00") Then
rng_data.Copy [currentWb.Sheets("sht").Range("F9").PasteSpecial xlPasteValues]
End If
Application.Run ("'C:\Users\redacted\Desktop\Booking Window Avai -working copy.xlsm'!UpdateACTUALSTrackingNoPrompt")
Application.Run ("'C:\Users\redacted\Desktop\Booking Window Avai -working copy.xlsm'!Email")
openWb.Close savechanges:=True
End Sub
它没有给我任何错误,它一直在运行。它实际上并没有粘贴任何值。