View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
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