Setting value of active workbook in Excel VBA

前端 未结 3 1786
长发绾君心
长发绾君心 2021-01-02 19:12

I for now have my workbook set up this way, in where the workbook is hard coded into the Set command, I am wondering if there is a way of doing this so I can have it where i

相关标签:
3条回答
  • 2021-01-02 19:50

    Try this.

    Dim Workbk as workbook
    Set Workbk = thisworkbook
    

    Now everything you program will apply just for your containing macro workbook.

    0 讨论(0)
  • 2021-01-02 19:54

    You're probably after Set wbOOR = ThisWorkbook

    Just to clarify

    ThisWorkbook will always refer to the workbook the code resides in

    ActiveWorkbook will refer to the workbook that is active

    Be careful how you use this when dealing with multiple workbooks. It really depends on what you want to achieve as to which is the best option.

    0 讨论(0)
  • 2021-01-02 20:01

    This is all you need

    Set wbOOR = ActiveWorkbook
    
    0 讨论(0)
提交回复
热议问题