Excel宏中的Visual Basic全局变量 [英] Visual Basic global variables in Excel Macro

查看:84
本文介绍了Excel宏中的Visual Basic全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VB上为Excel编写宏.有一个结构:

 表格表格1模组主要的 

在Form1中,我有Button单击事件

 公共子CommandButton1_Click()MsgBox GLOBALVAR'我需要在这里访问GLOBALVAR结束子 

在Main中,我有一个过程Test

 子测试GLOBALVAR ="VALUE"结束子 

我该如何实施?我无法创建

 模块GlobalVariables终端模块 

由于Excel不支持此构造!

解决方案

添加

公共MyGlobalVariable作为字符串

Module1

中的

它可以在您的用户表单中访问

I writing macro for excel on VB. There is a structure:

Forms
    Form1
Modules
    Main

In the Form1 I have Button click event

Public Sub CommandButton1_Click()
MsgBox GLOBALVAR 'I need access to GLOBALVAR here
End Sub

In the Main I have procedure Test

Sub Test
GLOBALVAR = "VALUE"
End Sub

How I can implement it? I can't create

Module GlobalVariables

End Module

Due to Excel does not support this construction!

解决方案

Add a

Public MyGlobalVariable as String

in the Module1

and it becomes accessible in your userform

这篇关于Excel宏中的Visual Basic全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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