View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Excel VBA as a programming language

Just to get you started, you could put code like this in the Thisworkbook
module, which will run Macro2 when you hit Alt-Left Arrow and Macro3 when you
hit Alt-Down Arrow.

Private Sub Workbook_Open()
Application.OnKey "%{LEFT}", "Macro2"
Application.OnKey "%{DOWN}", "Macro3"
End Sub


I would actually input the function in the cell with the period (ie
".gini()") and have Macro2 and Macro3 (which are in a generic module) test
the first character for a period and replace it with an = sign.

Sub Macro2()
With ActiveCell
If Left(.Text, 1) = "." Then _
.Formula = "=" & Right(.Formula, _
Len(.Formula) - 1)
End With
End Sub


Sub Macro3()
Dim rngCell As Range

For Each rngCell In Range(ActiveCell, _
ActiveCell.End(xlDown)).Cells
With rngCell
If Left(.Text, 1) = "." Then _
.Formula = "=" & Right(.Formula, _
Len(.Formula) - 1)
End With
Next rngCell
End Sub


You may need to change the range you want Macro3 to run on (I just have it
going until there is a break in the data - did you intend the entire column
below the activecell?).


"marco" wrote:

Hi group, this is my first time here. I'll get right away to the
point.

I'm trying to re-write a piece of software on Excel using the builted-
in Visual Basic engine (VBA) in order to communicate to GPIB devices
(instruments like spectrum analyzers and power meters). I'm trying to
create my own programming language on Excel; I'll explain.

On each cell, I should be able to write:

A1 =gini()
A2 =gfind(abc)
A3 =gout(abc, "GPIB command", B3)

=g* are all functions, and none of them return nothing.

These functions should NOT run when I enter them on any cells (on
pressing the ENTER key). Instead, it should not appear 0 (because the
function was executed and returned 0), but the function name like, for
example, .gini() and .gfind(abc) (note the dot). This way, I can
see the commands on the worksheet, instead of the result, and the
functions are not runned.

Then, on the current ActiveCell, if I press ALT+(left arrow), only the
function on that cell should run, and if I pressed ALT+(down arrow),
it should run all commands on all cells below.

Note, on the function bar I can see =gini(), but on the cell itself I
should see .gini(). Pressing ALT+(left arrow), =gini() (the gini()
function) should run.

I'm over this problem for almost a week, and I feel frustrated with my
results. Can anyone point me good directions on how to solve this
efficiently?

Best regards, and thank to you all in advance for reading,
Marco Ferra