Solved

ocx or dll file

Posted on 2004-08-03
8
242 Views
Last Modified: 2010-05-02
Dear Experts
I design two functions which return string for VBA and using them in MS Word.
now I want to store these function out side of ms word. means in an OCX or DLL file please guide me which one will be best and also how to design if u can guide or link me to a good tutor for that.

thanks
0
Comment
Question by:SCS_SU
  • 4
  • 3
8 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 11710454
A dll is a component/library that contains only code (subs, functions and classes). Whereas an ocx is an ActiveX control that you would place on a form, much like you would with a command button or textbox.

An ActiveX dll is fairly simple to create.

This tutorial should help you get started:

    http://www.tutorial-web.com/asp/dll/


Hope this helps.
0
 

Author Comment

by:SCS_SU
ID: 11710628
I want to access these function from VBA ms word.
demo looks as my function
I get argument and then return some value

Function AdditionFunction(FirstNumber, SecondNumber)
    AdditionFunction = FirstNumber + SecondNumber
End Function

lik looks nice
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 11710670
Once you have create an ActiveX dll (containing a class module) you need to create an instance of it in your VBA app using code like:

    Set oSomeObject = CreateObject("YourComponent.YourClassName")

You can then call your functions with code something like:

    myVal = oSomeObject.AdditionFunction(5, 10)


Hope this helps.
0
 
LVL 9

Expert Comment

by:s_sansanwal
ID: 11711237
Register it before using in VBA
run regsvr32.exe yourDll.dll
and then use the code written by Carl
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:SCS_SU
ID: 11739121
ohh I select a activex dll template in vb and in a class i put all my function. now wat to do.
also as in ms word template every body can see codes then how to restrict to not use this dll.

0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 20 total points
ID: 11739428
next you make your dll.  Then in you Word VBA project you add a reference to you dll using the Project > References menu.  To create an use an object in your dll you use something like:

    Dim myObj As New YourProjectName.YourClassName

    '// Call a method of your object
    myObj.DoSomething
0
 

Author Comment

by:SCS_SU
ID: 11811986
yes thanks it works fine but a little more in this

I have about 5 differnt types of functionalities in this
each function contain some other functions help and when I seprate them in modules it is ok but in calling user interface I just have function that I define in main class and if I define all functions in that it looks too heavy to handle so I want to make seprate modules for diff: catagories but want to allow my dll to show them too.

I tried to make them public but they allso do not work.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 11812374
To do that you would have to put a function in your class that calls the relevant function in your module. The only functions that are exposed directly to the user are the ones in the class that are Public.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now