VBA Automation Error

-Wayner-

Board Regular
Joined
Feb 8, 2008
Messages
84
Hi all,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
I have come across a seriously frustrating problem and one which i am genuinely completely stumped as to what the solution might be.<o:p></o:p>
<o:p></o:p>
I have a tool which uses a user defined function:<o:p></o:p>
<o:p></o:p>
Code:
[COLOR=black][FONT=Verdana]Function IsFormula(c)[/FONT][/COLOR]
[FONT=Verdana][COLOR=black]On Error Resume Next[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]IsFormula = c.HasFormula[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]End Function<o:p></o:p>[/COLOR][/FONT]
<o:p></o:p>
<o:p></o:p>
This drives the following formula:<o:p></o:p>
<o:p></o:p>
Code:
[COLOR=black][FONT=Verdana]=IF(ISERROR(IF(isformula(AE21),IF(AND(NOT(BP21=""),Apply_newrange_forecast="Yes"),AE21,IF(OR(Z21<D21*minfcastfactor,ABS(AC21-Z21)>Z21*fcastvarallow),AC21,Z21)*F21),AE21)),"",IF(isformula(AE21),IF(AND(NOT(BP21=""),Apply_newrange_forecast="Yes"),AE21,IF(OR(Z21<D21*minfcastfactor,ABS(AC21-Z21)>Z21*fcastvarallow),AC21,Z21)*F21),AE21))<o:p></o:p>[/FONT][/COLOR]
<o:p></o:p>
<o:p></o:p>
Amongst a few other smaller formulas in the document which run off the same user defined function.<o:p></o:p>
<o:p></o:p>
Everything works in my template document without any problems, and i can't foresee any issues or reasons why it would throw up an issue. I have used it multiple times - dropping data and in processing it as i need to.<o:p></o:p>
<o:p></o:p>
However something strange has started to occur. I use multiple versions of this document - all the same, but with different data dropped in to be processed. I am now finding that when i open some of the saved versions (but not all?!) the document throws up VBA 'Automation Error'. It gives me no more details than that.<o:p></o:p>
<o:p></o:p>
I select 'ok' (help is the only other option) and it brings up my vba project. I fi open the module containing the above code the first line is highlighted in yellow. If i exit the debugger it goes straight back to the auto error diag box, a vicious circle which prevents the user accessing their data.<o:p></o:p>
<o:p></o:p>
If i make a change to the code - by removing the on error line it them allows me back into the workbook, but none of the code stored in individual sheets works. (I have tried the function without the on error line and it still causes the same issue - where adding it solves the problem.<o:p></o:p>
<o:p></o:p>
Digging a bit deeper it appears that when the error occurs something strange is happening to my sheets in VBA - this is where my novice shows through (if it hasn't already!).<o:p></o:p>
<o:p></o:p>
For some reason my sheets have duplicated - <o:p></o:p>
<o:p></o:p>
Whereas before it would show<o:p></o:p>
<o:p></o:p>
Sheet1 (name)<o:p></o:p>
Sheet2 (name)<o:p></o:p>
<o:p></o:p>
etc.<o:p></o:p>
<o:p></o:p>
It now shows<o:p></o:p>
<o:p></o:p>
Sheet1<o:p></o:p>
Sheet2 (which initially appear in blue?) - with a different icon<o:p></o:p>
<o:p></o:p>
then my original sheet 1 is now shown as:<o:p></o:p>
<o:p></o:p>
Sheet7 (name)<o:p></o:p>
Sheet8 (name)<o:p></o:p>
<o:p></o:p>
These sheets do not contain the original code - this is located in the new sheet1 (with no name). Therefore none of my buttons in the worksheets work anymore.<o:p></o:p>
<o:p></o:p>
I hope this makes some sense as to what is happening. I am absolutely lost as to what is happening - it is almost as though the document is self-replicating its sheets which is stopping it from working. The difficulty is it doesn't even happen every time - it's only on certain sheets and it's proving really hard to isolate what the issue is!<o:p></o:p>
<o:p></o:p>
As a note i am using the document on Excel 2003 - Work Pc's, but when i try it on my laptop Excel 2010 it doesn't give me the automation error - but i still have instances where the buttons on the sheet don't work - i.e. the code and sheet names are moved around when viewed in VBA.<o:p></o:p>
<o:p></o:p>
Any ideas at all as to what might be causing this - and more so how i might rectify it would be absolutely hugely appreciated.<o:p></o:p>
<o:p></o:p>
If i need to try explain anything more clearly please let me know. I really hope someone knows what i am talking about or has seen this before...?!<o:p></o:p>
<o:p></o:p>
Thanks in advance for any help.<o:p></o:p>
<o:p></o:p>
Cheers<o:p></o:p>
Wayner<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
</D21*minfcastfactor,ABS(AC21-Z21)></D21*minfcastfactor,ABS(AC21-Z21)>
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
There's only one line of code so I don't think the On Error is necessary

try this

Code:
Function IsFormula(c As Range) As Boolean
  IsFormula = c.HasFormula
End Function
 
Upvote 0
Dave,

Thank you for the quick response. I have changed the code and am now trying to recreate the issue to see if it solves the problem.

Could his function erroring be causing all of the odd goings on with my sheets being effectively duplicating and therefore removing all the functionality of my document?

I'm just really struggling to comprehend what is going on!

Thanks again.
Wayner
 
Upvote 0
The issue you have identified in the above thread looks very similar to the one i am having, but the solution offered (regarding speech marks etc.) doesn't seem relevant to the issue i am experiencing.

It just seems such a strange problem!

I am not able to recreate the error at this moment (sods law in know!), so i will continue to run with the updated code and see if it happens moving forward. I'll post back with any further updates.

Thanks for your input - i welcome any further insight which might get me to the bottom of this issue.

Thanks
Wayner
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top