更改其他工作簿的单元格

时间:2018-09-19 12:53:32

标签: excel vba

我尝试更改其他工作簿的单元格“ A6”,所以我编写了这段代码,但是它不起作用,我不知道为什么,我尝试了不同的代码,但是仍然不起作用,你知道吗为什么?

谢谢

 Sub test()
    Dim wbSource As Workbook
    Dim shCurrency As Worksheet
    Set wbSource = Workbooks("BP19.xls")
    Set shCurrency = wbSource.Sheets("KPI")

       wbSource.shCurrency.Range("A6") = "LC"

End Sub

但是当我把它放进去

 Workbooks("BP19.xls").Worksheets("KPI").Range("A6") = "EUR"

1 个答案:

答案 0 :(得分:1)

摆脱wbSource前面的shCurrencyshCurrency已引用Sheet中的wbSource

Sub test()
    Dim wbSource As Workbook
    Dim shCurrency As Worksheet
    Set wbSource = Workbooks("BP19.xls")
    Set shCurrency = wbSource.Sheets("KPI") 

    shCurrency.Range("A6") = "LC" 

End Sub