Confusing Runtime Error

P

Pflugs

I'm getting a mismatch error when I install my custom add-in, but it doesn't
make sense. Below is my code:

Set myButton = myBar.Controls.Add(Type:=msoControlButton)
With myButton
If Application.Calculation = xlCalculationManual Then
.FaceId = 349
.TooltipText = "Click here to set calculation method to
AUTOMATIC."
Else
.FaceId = 346
.TooltipText = "Click here to set calculation method to MANUAL."
End If
end with

When Excel is first started, the error occurs at the
"Application.Calculation" line. However, when I enter the debugger and step
through, the code continues without error. If this add-in is installed after
the application has fully started, then there seems to be no problem.

I see that when no workbook is open, the Options settings are unavailable.
Is there any way to check if the application has fully started?

Thanks,
Pflugs
 
D

Dave Peterson

I think you'd be better served to not worry about any workbook being
opened--just create one yourself and close it when you're done.



Dim tempWkbk as workbook
Set tempwkbk = workbooks.add

'your code to add the buttons

'and then close the workbook
temwkbk.close savechanges:=false
 
P

Peter T

Application.Calculation, Read/Write, requires a visible workbook in place,
ie an active workbook. Defer your routine by calling with the Ontime method.
'Now' is OK, it won't run until everything related to Startup is done, in
particular an active workbook is present.

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top