我使用下面的代码打开一个文件,并将复制和粘贴数据,但是我收到编译错误
Duplicate declaration in current scope
当它给出编译错误时,突出显示wb As工作簿行。
Sub Test()
Dim wb As Workbook
Dim wksht As Worksheet
Dim rng As Range
Set wksht = Sheets("CBS001")
Set rng = wksht.Range("A5")
If Not IsEmpty(rng.Offset(1, 0)) Then
Set rng = Range(rng.End(xlDown).Offset(0, 14), rng.Offset(1, 0))
Selection.Copy
Set wb = Workbooks.Open(Filename:="H:\Finance\CBF\Invoices\Monthly Invoicing Summary\" & Format(Now, "yyyy") & "\ASM\" & Format(DateSerial(Year(Now), Month(Now) - 1, Day(Now)), "mmyy") & " ASM CBF Reg Summary.xlsx")
wb.SaveAs Filename:="H:\Finance\CBF\Invoices\Monthly Invoicing Summary Test\" & Format(Now, "yyyy") & "\ASM\" & Format(Now, "mmyy") & " ASM CBF Reg Summary.xlsx"
wb.Close
End If
End Sub
答案 0 :(得分:0)
问题是vba从我工作簿中的其他地方拾取了相同的Dim,因此我使用更长,更准确的名称。
Sub Test()
Dim wbdestination As Workbook
Dim wksdata As Worksheet
Dim rngdestination As Range
End Sub
例如