本文介绍了Excel宏-将ActiveWorkbook.Sheets(“")设置为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我打算大量使用下面的代码.

Hello I plan on using the code below alot.

Application.Goto (ActiveWorkbook.Sheets("clients").Range(""))



而不是大量编写ActiveWorkbook.Sheets(""),我如何将其作为变量.我尝试只将Dim变量作为string = that.但这给了我一个错误.有没有办法做到这一点?希望这应该很容易回答.在此先感谢.



Instead of writing the ActiveWorkbook.Sheets("") alot how do I make this as a variable. I tried just doing a Dim variable as string = that. But it gave me an error. Is there a way to do this? This should hopefully be easy to answer. Thanks in Advance.

推荐答案

Dim wsh As Worksheet
Dim rng As Range

Set wsh = ActiveWorkbook.Sheets("clients")
Set rng = wsh.Range("A1")

'your code...


'and after all
Set rng = Nothing
Set wsh = Nothing


这篇关于Excel宏-将ActiveWorkbook.Sheets(“")设置为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 10:55