Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB6 - Active x - Excel Linked Cell Property

Posted on 2009-07-13
1
Medium Priority
?
1,220 Views
Last Modified: 2013-12-20
I'd like to create an ocx control using vb6 for use in Excel (2003 version). I need the control to be linked to a cell in excel and display the value that is in the linked cell in a text box on the control. I've got as far as creating a property using get/set statement in the control, but can't seem to link it in to a cell in excel.... Any help much appreciated...
0
Comment
Question by:therealmongoose
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 10

Accepted Solution

by:
therealmongoose earned 0 total points
ID: 24852636

Thanks to anyone who took the time to look at my question - even if you thought that's a bit too much to explain... For your information, this is a first step towards and excel speedometer dial control (I want a neater solution than a pie chart graph) and need to read a cell value from the parent worksheet.

As a bit of a noob when it comes to building ocx controls in vb6, it's taken a fair amount of uphill learning to find the solution for this, so for the sake of someone elses sanity here's the answer...

The steps below are shown in a "for dummys" format, mainly on the grounds that this is what I would have liked to have found somewhere... :-)

To create an ocx object that reads from a linked cell in Excel...
Open vb6
Select Activex Control

First Create a User property:
---------------------------------------
 
From the projects menu, choose Add user control
Choose VB Control Interface Wizard and press open
Click next >
Remove all other properties (you can add them back in later if you need them) by clicking the double left button
Click next
Click New
Enter a name for your property (e.g. CellValue)
Click ok
Click Next > Next > Next > Finish

Then Link the property to a data binding:
--------------------------------------------------------
From the Tools menu choose Procedure Attributes
In the drop down find your property then click advanced
Select "User Interface default"
Select "Property is data bound"
Select "This Property binds to Datafield"
Select "Update Immediately"
Click OK

To test the control, stick a command button on the form in the on click event with the code:
MsgBox Me.CellValue
Build the ocx using File menu > Make Project1.ocx (save the file where you can find it!!)

Register the ocx on your PC
--------------------------------------
Open the cmd window (Start>run>cmd)
and register the ocx by typing
(assumes the ocx file is in c:\ root directory)
cd c:\
regsvr32 c:\project1.ocx
(to unregister the ocx use the U switch e.g. regsvr32 /u c:\project1.ocx

Test the Property:
------------------------
Open excel and insert a copy of your ocx - to do this you'll need to open the control toolbox (right click menu bar) and find the hammer and
spanner button - scroll down and find your control under Project1.UserControl1
Select the control and drop it in the worksheet
Right click the control and choose properties
If all has gone to plan there will be a LinkedCell property shown - Enter a cell reference (e.g. A1) then close the property window and click the design view button (blue triangle) on the control toolbox menu to turn off design mode.
Enter a value in cell A1
Click the command button on the ocx a couple of times (first click gets focus but does not seem to activate the on click event) The value of A1 should be shown in a message box...
Here's a couple of sites that have been useful with the above:
http://visualbasic.freetutes.com/learn-vb6-advanced/lesson13/p30.html http://pntpm3.ulb.ac.be/Info/Activex/ http://www.codeproject.com/KB/COM/ExcelActiveXArrow.aspx
Leave me a comment if this has helped you!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question