|
-
May 26th, 2006, 01:17 AM
#1
Thread Starter
Member
[RESOLVED] Decalring global variables in VBA
Hi, I am quite new to VBA and i wan to know how can i declare a global variable in VBA. I understand tat i need to put this definition in a module, something like header files in C.. but what else is require in the module?
can someone pls help me by giving me exactly the codes for declaring a golbal variable in a module?
Global Variable : toolPath
Type : String
so do i define as Public toolPath As String?? anything esle n where to place it? thks
btw, i am using VBA in access... so the "lifespan" of the variable will last till the entire application is closed right?
thks
Last edited by fulltime; May 26th, 2006 at 01:25 AM.
-
May 26th, 2006, 01:36 AM
#2
Re: Decalring global variables in VBA
You have yourself answered your question.
You add a module in your VBA project and then write
VB Code:
Public toolPath As String
This makes the variable available to all other modules.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
May 26th, 2006, 01:56 AM
#3
Thread Starter
Member
Re: Decalring global variables in VBA
 Originally Posted by Shuja Ali
You have yourself answered your question.
You add a module in your VBA project and then write
VB Code:
Public toolPath As String
This makes the variable available to all other modules.
thks.. wats the difference between a module and a class module?
-
May 26th, 2006, 01:57 AM
#4
Re: Decalring global variables in VBA
Moved
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 26th, 2006, 02:54 AM
#5
Thread Starter
Member
Re: Decalring global variables in VBA
wat if i want a function to return a value? how can i declare it?
Eg Function Name =
Private Sub Test()
i want it to return a string. how can i do it? thks...
-
May 26th, 2006, 03:00 AM
#6
Re: Decalring global variables in VBA
A Sub does not return anything at all. A Function does.
VB Code:
'In a standard Module:
Option Explicit
Public Function AnimalSound() As String
AnimalSound = "Meow.NET"
End Function
VB Code:
'Usage:
Private Sub Command1_Click()
MsgBox AnimalSound ' "Meow.NET"
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 26th, 2006, 03:05 AM
#7
Re: Decalring global variables in VBA
Class Module : It is basically a template using which objects can be created. The code that is written in the class module basically describes the attributes (methods, events, properties, fields) of the object that are created using that class module. Class modules are the foundation of OOP in VB.
Module: MOdules are basically the files where you write common procedures and declare public data that will be accessed throughout the application.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
May 26th, 2006, 03:15 AM
#8
Thread Starter
Member
Re: Decalring global variables in VBA
got it.. thks to the both of u
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|