尝试引用活动工作簿中的另一个工作表 [英] Trying to reference another worksheet in active workbook

查看:147
本文介绍了尝试引用活动工作簿中的另一个工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击命令按钮时,我正在努力使另一个工作表处于活动状态,但我仍然处于同一个活动工作簿中:

  Sub Submit_Warranty()
'将保修数据工作表设置为活动页
表(Sheet2)。激活

'显示提交保修用户表单
Warranty_Input 。显示
End Sub

我不断得到下标超出范围的错误。任何想法?

解决方案

如果您发布的代码是一切,那么这个错误几乎都来自无效的引用。所以我的猜测是,实际的显示名称就像Warranty_Data,而Sheet2很可能是VBA对象的名称(也许你反过来使用它们)。



有很多方法可以选择工作表,具有各种优点和缺点。当谈到按名称选择时,要注意的主要问题是该表格实际上分配了两个名称,您在所发布的代码中使用了两种选择方法。一个名称是工作表的工作簿选项卡中显示的名称,另一个名称是VBA内部的名称。以下是一个屏幕截图,以演示如何使用这两种类型的名称。




I am trying to make another worksheet active when command button is clicked, but I'm staying within the same active workbook:

Sub Submit_Warranty()
    'Set warranty data worksheet as active page
    Sheets("Sheet2").Activate

    'Show the submit warranty user form
    Warranty_Input.Show
End Sub

I keep getting "subscript out of range" error. Any ideas?

解决方案

If the code you posted is everything, then that error pretty much has to be from an invalid reference. So my guess would be that the actual displayed name is something like "Warranty_Data", while "Sheet2" is likely the VBA object name (maybe you're using them in reverse).

There are a lot of ways to select a worksheet, with various advantages and disadvantages. When it comes to selecting by name, the major gotcha to watch out for is that sheets actually have two names assigned, and you're employing both methods of selection in the code you posted. The one name is what's displayed in the sheet's workbook tab, the other name is internal to VBA. Here's a screenshot to demonstrate how to use both types of names.

这篇关于尝试引用活动工作簿中的另一个工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆