我正在尝试创建一个宏,它通过列“C”查看,在“C”列的每一行中包含“是”,然后自动打开带有“B2”链接的文件并显示文本在“F2”中,应该将值作为值复制并粘贴到范围“I2”中打开的文件中,然后使用新文件名保存文件,从“H2”开始,然后最终关闭文件。
下面是我试过的宏,但没有成功。
Sub Copy()
Dim SWB As Workbook
Dim TWB As Workbook
Dim NewFileName As String
Dim OldFileName As String
Dim rng As Range
Dim row As Range
Set SWB = ThisWorkbook
Set SWS = SWB.Sheets("Sheet1")
NewFileName = Range("H2").Value
OldFileName = Range("B2").Value
response = MsgBox("Have you reviewed the files? This is a notification.", vbYesNo, "Confirmation")
If response = vbNo Then
Exit Sub
End If
Application.ScreenUpdating = 0
Set rng = Range("A1:Q500")
For Each row In rng.Rows
If (Cells((i + 1), 3).Value) = "yes" Then
On Error Resume Next
With SWS.Range("F2").Copy
End With
Set TWB = Workbooks.Open(OldFileName)
With TWB.Sheets("CFF 12M")
.Range("I2").PasteSpecial Paste:=xlPasteValues
End With
TWB.SaveAs filename:=NewFileName
Application.CutCopyMode = False
TWB.Close Savechanges = True
End If
Next
End Sub