Solved

VB6 - Active x - Excel Linked Cell Property

Posted on 2009-07-13
1
1,203 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

752 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