How Can I Access a Subprogram on a Separate Screen in Excel?

  • Thread starter Thread starter TripleS
  • Start date Start date
  • Tags Tags
    Excel Programming
Click For Summary
SUMMARY

The discussion focuses on accessing a subprogram in Excel VBA that randomizes money values for a game similar to "Deal or No Deal." The user requires the randomization to execute upon opening the Excel file, but the subprogram is located on a separate screen within the Excel Objects. The solution involves declaring the subprogram as a Function in a standard VB module, allowing it to be called from 'This Workbook' using its name. This method ensures that the randomization code can be executed seamlessly when the workbook is opened.

PREREQUISITES
  • Familiarity with Excel VBA programming
  • Understanding of Excel Object Model
  • Knowledge of declaring Functions in VB modules
  • Experience with event-driven programming in Excel
NEXT STEPS
  • Learn how to declare Functions in Excel VBA modules
  • Research Excel Workbook Open event handling
  • Explore the Excel Object Model for better code organization
  • Study best practices for modular programming in VBA
USEFUL FOR

Excel developers, VBA programmers, and anyone creating interactive Excel applications or games will benefit from this discussion.

TripleS
Messages
22
Reaction score
0
I am using the VB script that is already in Excel, and I am making a program similar to that "Deal or No Deal" show that airs in many countries.
The concept of the game is where there is a certain number of briefcases, and there is a money value in each of those. You choose one, and slowly choose other briefcases. The aim is to keep the most money in the unopened briefcases to generate the largest bank offer (where a 'bank' tries to buy your briefcase on the chance of that briefaces to have a certain amount of money)

In the main game screen where one chooses the briefcase I have put in a code the randomises the 18 possible money values for the 18 briefcases. I need that randomisation to occur when Excel is opened up, but the subprogram with the randomisation and intialisation of variables is on a separate screen (which has its own code), which I cannot access from the 'This Workbook' screen.

Does anyone know of a way to bypass this, so i can access the subprogram i need?
 
Technology news on Phys.org
Not sure that I completely understand your problem, or what it is you want to do but...

If you declare a Function in a VB module, Excel will use it just as it uses any Excel function. So if I declare

Function XYZ( a as integer, b as double)
.
.
end

I can then write = XYZ(a1, a2) in a cell. Excel will execute the VB function.
 
okay...let me try and reiterate
There is a subprogram that randomises the money values for each briefcase
that is in a particular spot (in a 'screen' of Microsoft Excel Objects), and i need that section of code to run when the program is opened up. But if i simply put GameSetup (name of the subprogram), it doesn't know where it is, and if i put the whole code in, it can't find that the objects to which the code is attached to...

hope you got that
 

Similar threads

  • · Replies 18 ·
Replies
18
Views
6K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 5 ·
Replies
5
Views
1K
Replies
5
Views
6K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
Replies
7
Views
7K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
9
Views
3K