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