从每月更改名称的工作表中提取数据

我每个月都下载一个文件。 我从其中一张表中提取数据并粘贴到另一个文件中。 我将整个过程自动化 – 唯一的问题是它的工作表每个月都会更改名称,但是它只会从1703更改为1704到1705等。我已经使用以下代码识别了此更改:

Dim newDate: newDate = Format(DateAdd("M", -1, Now), "YYMM") 

并且我下载的工作表和工作簿的名称将是:

  filename = "BSR" & "_" & newDate & ".xlsx" 

我怎么能把它放在复制粘贴代码。 即:

  wbsecond.Sheets("filename").Range("A1:AD1105").Copy _ Destination:=wbfirst.Sheets("FX").Range("A1") 

整个代码如下:

  Sub fx() Dim filename As String Dim newDate: newDate = Format(DateAdd("M", -1, Now), "YYMM") Dim wbfirst As Workbook Dim wbsecond As Workbook Dim staticFolder As String Dim dateformat As String 'location of the parent folder staticFolder = "\C:abnsd\location\sublocation\test\" 'provides previous month YYYYMM dateformat = Format(DateAdd("M", -1, Date), "yyyymm", 1) 'workbook with the code Set wbfirst = ThisWorkbook filename = "BSR" & "_" & newDate & ".xlsx" Workbooks.Open "https://fakeurl.com/site0266/FX/Global%20FX%20Rates/" & filename ActiveWorkbook.SaveAs staticFolder & "\" & dateformat & "\" & "Source files" & "\" & "FX" & " - " & dateformat & ".xlsx" Stop 'workbook that needs to be copied over from Set wbsecond = Application.Workbooks.Open(staticFolder & "\" & dateformat & "\" & "Source files" & "\" & "FX" & " - " & dateformat & ".xlsx", _ UpdateLinks:=0) wbsecond.Sheets("filename").Range("A1:AD1105").Copy _ Destination:=wbfirst.Sheets("FX").Range("A1") wbsecond.Close savechanges:=False MsgBox "You have successfully transferred the FX File of " & dateformat End Sub