VBA:数组和全局变量声明 [英] VBA: Arrays and Global Variable Declarations

查看:2916
本文介绍了VBA:数组和全局变量声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要声明的VBA数组将由每一个函数使用。但是,我不能宣布它作为一个全球性的,因为我想用C ++做

I need to declare an array in VBA that will be used by every function. However, I cannot declare it as a global as I would do in C++.

我的code是如下:

Option Explicit
 Dim test(0 to 10) as String

 test(0) = "avds"
 test(1) = "fdsafs"
 ....

下面概念化什么,我试图做的。

The following conceptualizes what I am trying to do.

 public function store() as boolean
  Worksheets("test").cells(1,1) = test(0)
 End Function

我怎样才能实现这个功能?

How can I achieve this functionality?

推荐答案

有关全局声明,昏暗转变为公共像这样:

For global declaration, change Dim to Public like so:

Public test(0 to 10) as String

您可以调用这个样(假设它是在模块1,否则更改模块1,无论你已经把它命名为):

You can call this like (assuming it is in Module1, else change Module1 to whatever you've named it):

Module1.test(0) = "something"

或者干脆:

test(0) = "something"

这篇关于VBA:数组和全局变量声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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