Posted to microsoft.public.excel.programming
|
|
Using a dll in vba
I never done this before. Could you tell me where I could find some source
code so I can figure out how to do this?
David
"NickHK" wrote:
David,
You sub "cleanup" is in the DLL ?
If so, then it has no idea what Workbooks(3) refers to, as it is NOT in
Excel.
At the least, you would have to pass a reference to the DLL of the Excel
instance.
e.g.
'In the DLL
Public sub CleanUp(argWhichExcel As Excel.Application)
With argWhichExcel.Workbooks(3).Worksheets(2).
....etc
But it may be better to create a class (or extra sub arguments) to
explicitly set the Excel instance, WB, WS, range etc, then call .CleanUp.
Otherwise your DLL code is limited to a single fixed task, which kind of
defeats the point of putting it in a separate DLL in the first place.
NickHK
"David" wrote in message
...
It works...but now I am getting a subscript out of range error. The first
part of the cleanup sub is:
For z = 1 To 10
For x = 16 To 45
If Workbooks(3).Worksheets(2).Range("A" & x).Value = "" Then
Rows(x).Select
Selection.Delete
End If
Next x
Next z
x and z are declared as public and the workbook and worksheet numbers are
correct. None of the other buttons work either. Would it help if I used
with
statements?
"Chip Pearson" wrote:
You cannot create normal Windows DLLs in Visual Basic. You can
create ActiveX DLLs. You can then call them with code like
Dim MyObject As DLLProjectName.MyObjectClass
Set MyObject = New DLLProjectName.MyObjectClass
MyObject.ProcedureName
You'll need to set a reference to the DLLProjectName. In VBA, go
to the Tools menu, choose References, and select your
DLLProjectName from the list.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
"David" wrote in message
...
I created a dll in vb 5. I am trying to use the dll in a
spreadsheet but I am
getting the runtime error 453 "Can't find DLL entry Point"
(using excel 2000)
I have the following code in a module:
Declare Sub cleanup Lib "f:\final inspection\master
templates\final_inspection" ()
I have the following code in a button on the sheet:
Sub cmdcleanup_Click()
cleanup
End Sub
The sub cleanup is public in the dll and I have also created
referances in
the workbook to the dll.
David
|