首先是代码:
Sub Test()
Dim rng As Range
Dim cell As Range
Dim oldfilestring As String
Dim filestring As String
Set rng = Range("Files")
oldfilestring = "File A"
For Each cell In rng
filestring = cell.Value
ActiveWorkbook.ChangeLink Name:=oldfilestring, NewName:=filestring, Type:=xlExcelLinks
CopyPasteFilteredData
oldfilestring = filestring
Next cell
End Sub
我遇到麻烦的地方" oldfilestring ='文件A',有时第一个文件不是"文件A" - 如何编辑它使其成为列表中的第一个文件?
答案 0 :(得分:0)
如果rng
与您的文件列表相对应,那么您可以将列表中的第一个单元格设置为oldfilestring
字符串
Sub Test()
Dim rng As Range
Dim cell As Range
Dim oldfilestring As String
Dim filestring As String
Set rng = Range("Files")
oldfilestring = rng.Cells(1, 1).value
For Each cell In rng
filestring = cell.Value
ActiveWorkbook.ChangeLink Name:=oldfilestring, NewName:=filestring, Type:=xlExcelLinks
CopyPasteFilteredData
oldfilestring = filestring
Next cell
End Sub