Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default First Time VBA user- really easy question :-)


I'm maintaining some VBA code for Excel 2003, developed by a person no
longer employed where I work.

This code contains several small forms, and work sheets.

One the main worksheet, there are several command buttons, (and the
event handlers for these buttons as well)

I want to add a version number to the program, so that the string
variable is defined as a constant in the VB code, but is displayed on
the main worksheet.

I've defined the constant as follows
Private Const ProgramVersionNumber As String = "1.1"

Now, I want to display this in a cell on the main worksheet.

1. How do I print/display the value of this variable (from the VB
code) in Cell A1, ?
2. Can I reference this variable (or any variables in the VB code)
from the worksheet? If so, what is the syntax for doing this?
I've tried entering =ProgramVersionNumber in Cell A1, but that doesn't
work.

I could use some beginners references for Excel VBA.

I'm pretty comfortable with Visual Basic (VB6 to be precise), but I
rarely work with Excel, let alone driving Excel from VBA code.

thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default First Time VBA user- really easy question :-)

You can't directly read the version number from a worksheet cell. You need a
function in a module (create from "Insert" menu in VBA) that will read the
constant and return its value to the worksheet cell. E.g.,

Public Function GetVersion()
GetVersion = ProgramVersionNumber
End Function

Then, you can call this from a worksheet cell with

=GetVersion()


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting LLC
www.cpearson.com
(email on the web site)



"cappy2112" wrote in message
ups.com...

I'm maintaining some VBA code for Excel 2003, developed by a person no
longer employed where I work.

This code contains several small forms, and work sheets.

One the main worksheet, there are several command buttons, (and the
event handlers for these buttons as well)

I want to add a version number to the program, so that the string
variable is defined as a constant in the VB code, but is displayed on
the main worksheet.

I've defined the constant as follows
Private Const ProgramVersionNumber As String = "1.1"

Now, I want to display this in a cell on the main worksheet.

1. How do I print/display the value of this variable (from the VB
code) in Cell A1, ?
2. Can I reference this variable (or any variables in the VB code)
from the worksheet? If so, what is the syntax for doing this?
I've tried entering =ProgramVersionNumber in Cell A1, but that doesn't
work.

I could use some beginners references for Excel VBA.

I'm pretty comfortable with Visual Basic (VB6 to be precise), but I
rarely work with Excel, let alone driving Excel from VBA code.

thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default First Time VBA user- really easy question :-)

On Jun 18, 12:02 pm, "Chip Pearson" wrote:
You can't directly read the version number from a worksheet cell. You need a
function in a module (create from "Insert" menu in VBA) that will read the
constant and return its value to the worksheet cell. E.g.,

Public Function GetVersion()
GetVersion = ProgramVersionNumber
End Function


Thanks-
Using a function makes better sense than accessing a variable (or
const) directly.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default First Time VBA user- really easy question :-)

On Jun 18, 12:02 pm, "Chip Pearson" wrote:
You can't directly read the version number from a worksheet cell. You need a
function in a module (create from "Insert" menu in VBA) that will read the
constant and return its value to the worksheet cell. E.g.,

Public Function GetVersion()
GetVersion = ProgramVersionNumber
End Function

Then, you can call this from a worksheet cell with

=GetVersion()


Ok- I've tried this, but the spreadsheet still shows #NAME?

Public Function GetVersion()
GetVersion = ProgramVersionNumber
End Function

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default First Time VBA user- really easy question :-)

The code must be in a regular code module (create from Insert menu in VBA)
in the same workbook as the sheet from which you are calling the function.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"cappy2112" wrote in message
ps.com...
On Jun 18, 12:02 pm, "Chip Pearson" wrote:
You can't directly read the version number from a worksheet cell. You
need a
function in a module (create from "Insert" menu in VBA) that will read
the
constant and return its value to the worksheet cell. E.g.,

Public Function GetVersion()
GetVersion = ProgramVersionNumber
End Function

Then, you can call this from a worksheet cell with

=GetVersion()


Ok- I've tried this, but the spreadsheet still shows #NAME?

Public Function GetVersion()
GetVersion = ProgramVersionNumber
End Function




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default First Time VBA user- really easy question :-)

On Jun 18, 12:32 pm, "Chip Pearson" wrote:
The code must be in a regular code module (create from Insert menu in VBA)
in the same workbook as the sheet from which you are calling the function.


Not sure I understand what is different from what exists now, and what
you are suggesting.

There is already existing VBA code associated with this workbook-
specifically, the worksheet in question.
That is- when I double click on a command button on that worksheet,
the VBA event handler is displayed.

Is this relationship between workbook/worksheet & VBA code what your
referring to ?

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default First Time VBA user- really easy question :-)

Do NOT put the code in the code module associated with a worksheet. Re-read
my replies. You need to CREATE A NEW MODULE.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"cappy2112" wrote in message
ups.com...
On Jun 18, 12:32 pm, "Chip Pearson" wrote:
The code must be in a regular code module (create from Insert menu in
VBA)
in the same workbook as the sheet from which you are calling the
function.


Not sure I understand what is different from what exists now, and what
you are suggesting.

There is already existing VBA code associated with this workbook-
specifically, the worksheet in question.
That is- when I double click on a command button on that worksheet,
the VBA event handler is displayed.

Is this relationship between workbook/worksheet & VBA code what your
referring to ?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
easy use 12 month planner, complex elements, basic user, help A cry for help Excel Worksheet Functions 1 February 12th 07 12:10 AM
Freqencies over Time, in Columns -- Easy Question Rothman Excel Worksheet Functions 0 September 30th 06 04:27 AM
new user with easy question? not easy for me speakeztruth New Users to Excel 5 June 3rd 05 09:40 PM
User Defined Functions - Help Text - Make it Easy for the User Andibevan[_2_] Excel Programming 4 March 17th 05 09:51 AM
*Easy* question this time! aapp81[_10_] Excel Programming 2 November 25th 03 05:55 PM


All times are GMT +1. The time now is 02:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"