recording macro interating anoth

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Recording a macro (interating with another application) using VB

Recording a macro (interating with another application) using VB

resolvedResolved · Urgent Priority · Version 2010

Lone has attended:
Excel VBA Intermediate course

Recording a macro (interating with another application) using VB

Hi,

(1) I am using Solver to execute the physical details of an optimization model I have built within a spreadsheet. I am building a graphical user interface using Excel 2010 VBA to allow users to interact with the model I have built without exposing them to details of the model or Solver. I have a command button in my main GUI screen labelled "Solve current problem" to be clicked by a user following data entry into some input forms that send data to respect cells in the spreadsheet. How can I link this command button such that it mimicks the pressing of the "solve" button in Solver, to allow the user to interact with the solver application without exposing the user to Solver? (i.e., I wish for the user to click the command button "solve current problem" in my main GUI screen such that this command button activates or executes the solve button in Solver, which produces some outputs displayed within the spreadsheet)?

(2) What is the best way to pull out the above outputs produced by Solver and displayed in different places within the same worksheet, using VBA, such that I can display them to the user in the form of summary tables?

I look forward to your response and expertise.

Edited on Thu 2 Oct 2014, 23:42

RE: Recording a macro (interating with another application) usin

Hi Lone,

Thank you for the forum question.

You can use the macro recorder to do what you want. Record you are using the solver to solve what you want the solver to solve. The Solver will not be exposed to the user because you will need to close the solver to stop the macro recorder.

If you have the command button in a private module for a userform just type CALL + the name of the recorded macro in the on_click event.

You will need to refer the solver library. Please have a look at this link:
http://msdn.microsoft.com/en-us/library/office/ff839427 (v=office.15).aspx

Note
The Solver add-in is not enabled by default. Before you can use this function, you must have the Solver add-in enabled and installed. For information about how to do that, see Using the Solver VBA Functions. After the Solver add-in is installed, you must establish a reference to the Solver add-in. In the Visual Basic Editor, with a module active, click References on the Tools menu, and then select Solver under Available References. If Solver does not appear under Available References, click Browse, and then open Solver.xlam in the \Program Files\Microsoft Office\Office14\Library\SOLVER subfolder.

Question 2:

You are defining where you want the output from the solver in the solver dialog box, so when you click the command button the solver will call the macro where the output is defined.


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Recording a macro (interating with another application) usin

Hi Jens,

Thank you for your prompt response. That is fantastic.

Q1. Just to clarify, I will need to record a macro by going into Solver and doing what I need to do, then stop the recording and save the recorded macro and link it to the command button in VBA (will read more about recording a macro).

Q2. I am not sure I understand your response to item 2. Please clarify for me? Maybe I should clarify my question further as follows: I already have the outputs produced after clicking "solve" in Solver. These outputs (the results of Solver computations) are displayed on my spreadsheet that I used to build the model in different places within cells under rows (identifiers) and columns (headings/titles). By different places on the same worksheet I mean say rows 3 to 10, rows 20 to 25, rows 800 to 810, etc). The data in these cells are integers and decimals. The task is to pull out these data (specific cells) from a huge spreadsheet and display it back to the user in the form of summary tables, after user clicks "solve current problem" in the GUI screen. I am kindly looking to know the relevant VBA topic, method, procedure that I can use to pull out these data (already seating in different cells on my spreadsheet as an outcome of the Solver engine). For example, is it about using forms or using Pivot Tables, etc - such that I can read about the relevant/correct topic, method or specific procedure in my VBA manual and Books? My apologies for any confusion in framing my question number 2.

Kindest regards,

RE: Recording a macro (interating with another application) usin

Hi Lone,

Q1

To record a macro just click the VIEW tab in the Excel ribbon and in the last group (Macros) click Record macro. In the macro dialog box give the macro a name and click OK. Open the Solver add the needed parameters and constrains and click solve. Close the Solver dialog box and click the VIEW tab, click MACROS and STOP RECORDING. You will now find the macro you recorded in a module in the visual basic editor. Add a on_click event to the command button (as we did to the OK and Cancel command button). If you called the macro you recorded for RunSolver you need in the on_click event to typer CALL RunSolver.

Q2

If you want a summary output from a large worksheet a Pivot Table is a good solution, but then the source data need to be organised in a flat list, You will find the Pivot Table tool if you click the INSERT tab. We are working with VBA pivot tables on our advanced VBA course.


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Recording a macro (interating with another application) usin

Hi Jens,

Thank you so much for your prompt response. It is much appreciated.

Kindest regards,

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Using basic functions without doing formulas

When you highlight figures Autocalc tells you the total in the bottom right of the screen, but if you right click on the sum it will give you some basic functions. The functions are Min, Max, Average, Sum, Count, and Count Nums.

View all Excel hints and tips


Server loaded in 0.09 secs.