Solved

ocx or dll file

Posted on 2004-08-03
8
248 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
[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
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

739 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