[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Creating dll that uses Excel

avi

1/24/2012 3:52:00 PM

Hello,

When I try to recomplile a dll that has a reference to Excel, I get an
error msg "Permission denied" so that I must close Excel before
recompiling. Very annoying!

Trying to unregistered the dll does not help

Any idea?

Many thanks
Avi
8 Answers

DaveO

1/24/2012 4:20:00 PM

0


"avi" <aviben@bezeqint.net.il> wrote in message
news:053d7dfd-1d0c-4ad8-9e29-cc1826846854@hs8g2000vbb.googlegroups.com...
> Hello,
>
> When I try to recomplile a dll that has a reference to Excel, I get an
> error msg "Permission denied" so that I must close Excel before
> recompiling. Very annoying!
>
> Trying to unregistered the dll does not help
>
> Any idea?
>
> Many thanks
> Avi

Hi

If you mean you've ticked the "Microsoft Excel 11.0 Object Library" in the
References window you could try getting rid of that and moving to late
binding.

Regards
DaveO.


MikeD

1/24/2012 5:08:00 PM

0


"avi" <aviben@bezeqint.net.il> wrote in message
news:053d7dfd-1d0c-4ad8-9e29-cc1826846854@hs8g2000vbb.googlegroups.com...
> Hello,
>
> When I try to recomplile a dll that has a reference to Excel, I get an
> error msg "Permission denied" so that I must close Excel before
> recompiling. Very annoying!
>
> Trying to unregistered the dll does not help
>
> Any idea?


What *exactly* have you referenced? In other words, what file?

Mike


MikeD

1/24/2012 5:26:00 PM

0


"avi" <aviben@bezeqint.net.il> wrote in message
news:053d7dfd-1d0c-4ad8-9e29-cc1826846854@hs8g2000vbb.googlegroups.com...
> Hello,
>
> When I try to recomplile a dll that has a reference to Excel, I get an
> error msg "Permission denied" so that I must close Excel before
> recompiling. Very annoying!
>
> Trying to unregistered the dll does not help
>


Something else could be that you're not properly "disconnecting" from Excel
when your application (your DLL) terminates, or your DLL is not terminating
properly. IOW, you're not cleaning things up like you should be.

You need to provide more details.

Mike


avi

1/24/2012 6:52:00 PM

0

On 24 jan, 19:26, "MikeD" <nob...@nowhere.edu> wrote:
> "avi" <avi...@bezeqint.net.il> wrote in message
>
> news:053d7dfd-1d0c-4ad8-9e29-cc1826846854@hs8g2000vbb.googlegroups.com...
>
> > Hello,
>
> > When I try to recomplile a dll that has a reference to Excel, I get an
> > error msg "Permission denied"  so that I must close Excel before
> > recompiling. Very annoying!
>
> > Trying to unregistered the dll does not help
>
> Something else could be that you're not properly "disconnecting" from Excel
> when your application (your DLL) terminates, or your DLL is not terminating
> properly. IOW, you're not cleaning things up like you should be.
>
> You need to provide more details.
>
> Mike

This a very basic example that trigger the "Permission denied" msg

Sub Main()
Dim objApp As Object
On Error Resume Next
Set objApp = GetObject(, "Excel.Application")
Set objApp = Nothing
On Error GoTo 0
End Sub

The class:
Public Function TestDll(ooo As Variant)
If ooo = 5636.25698 Then Main
End Function

The project reference to "Microsoft Excel 14.0 object library"

Thaks again
Avi

MikeD

1/25/2012 9:20:00 PM

0



"avi" <aviben@bezeqint.net.il> wrote in message
news:eb2138b9-4fd6-48aa-87ed-cae1c86d4e45@c6g2000vbk.googlegroups.com...
> On 24 jan, 19:26, "MikeD" <nob...@nowhere.edu> wrote:
>> "avi" <avi...@bezeqint.net.il> wrote in message
>>
>> news:053d7dfd-1d0c-4ad8-9e29-cc1826846854@hs8g2000vbb.googlegroups.com...
>>
>> > Hello,
>>
>> > When I try to recomplile a dll that has a reference to Excel, I get an
>> > error msg "Permission denied" so that I must close Excel before
>> > recompiling. Very annoying!
>>
>> > Trying to unregistered the dll does not help
>>
>> Something else could be that you're not properly "disconnecting" from
>> Excel
>> when your application (your DLL) terminates, or your DLL is not
>> terminating
>> properly. IOW, you're not cleaning things up like you should be.
>>
>> You need to provide more details.
>>
>> Mike
>
> This a very basic example that trigger the "Permission denied" msg
>
> Sub Main()
> Dim objApp As Object
> On Error Resume Next
> Set objApp = GetObject(, "Excel.Application")
> Set objApp = Nothing
> On Error GoTo 0
> End Sub
>
> The class:
> Public Function TestDll(ooo As Variant)
> If ooo = 5636.25698 Then Main
> End Function
>
> The project reference to "Microsoft Excel 14.0 object library"
>


That looks a little unorthodox to me. A Sub Main is typically used as your
startup object and you typically do not specify a startup object for a DLL.
Did you specify Sub Main as the startup object for the DLL? You do realize
that with GetObject, Excel MUST already be running, right? If it's not
already running, you'll get an "ActiveX component can't create object"
error. So, typically, what you'd do is this:

Dim objApp As Object
On Error Resume Next
Set objApp = GetObject(, "Excel.Application")
If objApp Is Nothing Then
Set objApp = CreateObject("Excel.Application")
objApp.Visible = True
mbInstanceCreated = True
End If

If mbInstanceCreated Then
objApp.Quit
End If

Set objApp = Nothing

On Error GoTo 0


The variable mbInstanceCreated should have sufficient scope (module level or
perhaps even global). You use that so you'll know to quit Excel if you
created the instance, or leave Excel running if didn't start it yourself.

If Excel is running, it makes perfect sense you'd get the permission denied
error. Excel is one of the few libraries for which you reference the .EXE
file directly rather than a type library file (either a .tlb or .olb file).
So yeah, you very well may need to quit Excel before you compile.

Of course, since you're using late-binding you don't even NEED to reference
the Excel object library and the problem should go away.

Mike





ralph

1/26/2012 7:15:00 AM

0

On Tue, 24 Jan 2012 10:51:32 -0800 (PST), avi <aviben@bezeqint.net.il>
wrote:

>On 24 jan, 19:26, "MikeD" <nob...@nowhere.edu> wrote:
>> "avi" <avi...@bezeqint.net.il> wrote in message
>>
>> news:053d7dfd-1d0c-4ad8-9e29-cc1826846854@hs8g2000vbb.googlegroups.com...
>>
>> > Hello,
>>
>> > When I try to recomplile a dll that has a reference to Excel, I get an
>> > error msg "Permission denied"  so that I must close Excel before
>> > recompiling. Very annoying!
>>
>> > Trying to unregistered the dll does not help
>>
>> Something else could be that you're not properly "disconnecting" from Excel
>> when your application (your DLL) terminates, or your DLL is not terminating
>> properly. IOW, you're not cleaning things up like you should be.
>>
>> You need to provide more details.
>>
>> Mike
>
>This a very basic example that trigger the "Permission denied" msg
>
>Sub Main()
> Dim objApp As Object
> On Error Resume Next
> Set objApp = GetObject(, "Excel.Application")
> Set objApp = Nothing
> On Error GoTo 0
>End Sub
>
>The class:
>Public Function TestDll(ooo As Variant)
> If ooo = 5636.25698 Then Main
>End Function
>
>The project reference to "Microsoft Excel 14.0 object library"
>
>Thaks again
>Avi

This very un`enlightening.

Remove the 'On Error Resume Next'. If you are trying to debug
something why ignore any possible errors?

The trailing 'On Error GoTo 0' is rather useless.

The Project Reference has nothing to do with anything as you are using
Late Binding. The argument to GetObject is not the Type Library ID it
is a ProgID. You might look in the Registry under ProgID to see what
is registered for that ID.

Replace the GetObject with CreateObject and see if you don't get
another error - ActiveX not found perhaps?

Where does the class/TestDLL come in?

Is this a clean project? Just a .BAS and the .CLS modules?

-ralph

avi

1/29/2012 9:37:00 PM

0

On 25 jan, 23:19, "MikeD" <nob...@nowhere.edu> wrote:
> "avi" <avi...@bezeqint.net.il> wrote in message
>
> news:eb2138b9-4fd6-48aa-87ed-cae1c86d4e45@c6g2000vbk.googlegroups.com...
>
>
>
>
>
>
>
>
>
> > On 24 jan, 19:26, "MikeD" <nob...@nowhere.edu> wrote:
> >> "avi" <avi...@bezeqint.net.il> wrote in message
>
> >>news:053d7dfd-1d0c-4ad8-9e29-cc1826846854@hs8g2000vbb.googlegroups.com....
>
> >> > Hello,
>
> >> > When I try to recomplile a dll that has a reference to Excel, I get an
> >> > error msg "Permission denied"  so that I must close Excel before
> >> > recompiling. Very annoying!
>
> >> > Trying to unregistered the dll does not help
>
> >> Something else could be that you're not properly "disconnecting" from
> >> Excel
> >> when your application (your DLL) terminates, or your DLL is not
> >> terminating
> >> properly. IOW, you're not cleaning things up like you should be.
>
> >> You need to provide more details.
>
> >> Mike
>
> > This a very basic example that trigger the "Permission denied" msg
>
> > Sub Main()
> >    Dim objApp As Object
> >    On Error Resume Next
> >    Set objApp = GetObject(, "Excel.Application")
> >    Set objApp = Nothing
> >    On Error GoTo 0
> > End Sub
>
> > The class:
> > Public Function TestDll(ooo As Variant)
> >    If ooo = 5636.25698 Then Main
> > End Function
>
> > The project reference to "Microsoft Excel 14.0 object library"
>
> That looks a little unorthodox to me. A Sub Main is typically used as your
> startup object and you typically do not specify a startup object for a DLL.
> Did you specify Sub Main as the startup object for the DLL? You do realize
> that with GetObject, Excel MUST already be running, right? If it's not
> already running, you'll get an "ActiveX component can't create object"
> error. So, typically, what you'd do is this:
>
>     Dim objApp As Object
>     On Error Resume Next
>     Set objApp = GetObject(, "Excel.Application")
>     If objApp Is Nothing Then
>         Set objApp = CreateObject("Excel.Application")
>         objApp.Visible = True
>         mbInstanceCreated = True
>     End If
>
>     If mbInstanceCreated Then
>         objApp.Quit
>     End If
>
>     Set objApp = Nothing
>
>     On Error GoTo 0
>
> The variable mbInstanceCreated should have sufficient scope (module level or
> perhaps even global).  You use that so you'll know to quit Excel if you
> created the instance, or leave Excel running if didn't start it yourself.
>
> If Excel is running, it makes perfect sense you'd get the permission denied
> error. Excel is one of the few libraries for which you reference the .EXE
> file directly rather than a type library file (either a .tlb or .olb file).
> So yeah, you very well may need to quit Excel before you compile.
>
> Of course, since you're using late-binding you don't even NEED to reference
> the Excel object library and the problem should go away.
>
> Mike

Thanks to all of you

BTW, the dll is used by an Excel addin so that there is always an
Instance of Excel running

Avi

GS

1/30/2012 8:04:00 PM

0

on 1/29/2012, avi supposed :
> BTW, the dll is used by an Excel addin so that there is always an
> Instance of Excel running

In this case, the Excel addin should make calls to the DLL (assuming
the DLL is properly registered on the user's machine). In this case
there's no need IMO for the DLL to GetObject or CreateObject since the
addin using the DLL must (by attrition) be running in some instance of
Excel.

If your addin needs your DLL to act on the Excel object calling it then
that ref is passed to the DLL when it receives the call from the addin
running within Excel because both the addin & DLL are running
'InProcess'.

--
Garry

Free usenet access at http://www.eternal-sep...
ClassicVB Users Regroup! comp.lang.basic.visual.misc