Solved

ocx or dll file

Posted on 2004-08-03
8
244 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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
 

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

772 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