Small VBA module causing "Automation Error Catastrophic Failure"

Yogojojo

New Member
Joined
Dec 28, 2018
Messages
3
Hi folks, this must be a super simple answer, but my Google-fu is utterly failing me. I have the following module in a workbook hosted on a Sharepoint server (Office 2010,2013,2016 users access the file)

Public Function DelParens(ByVal str As String) As String
While InStr(str, "(") > 0 And InStr(str, ")") > InStr(str, "(")
str = Left(str, InStr(str, "(") - 1) & Mid(str, InStr(str, ")") + 1)
Wend
DelParens = Trim(str)
End Function

The purple line is the code that is highlighted in the debugger.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
if you click on # icon above post window

... and paste code between the code tags which appear [ CODE ] paste code here [ /CODE ]

..... your code looks as in does in a VBA module, making it easier to read

Code:
Public Function DelParens(ByVal myStr As String) As String
    While InStr(myStr, "(") > 0 And InStr(myStr, ")") > InStr(myStr, "(")
        myStr = Left(myStr, InStr(myStr, "(") - 1) & Mid(myStr, InStr(myStr, ")") + 1)
    Wend
    DelParens = Trim(myStr)
End Function

Variable str replaced with myStr in above function
- to reduce risk of problems it is better to avoid using variable names that are identical to VBA function names etc
- STR is a VBA function (follow this link to learn about STR function)
- whilst being safer practice, I do not think that this is necessarily related to your problem :confused:

You have not given details to allow your problem to be recreated and simply calling the function works fine for me.

When does code fail?
- when the workbook is opened?
- when any code runs?
- only when function DelParens is called?

How are you calling DelParens?
 
Last edited:
Upvote 0
Is your UDF working correctly for you in a normal Excel workbook not hosted on Sharepoint and just not when hosted on Sharepoint?
 
Upvote 0
Hi there, thanks for the reply!

Variable str replaced with myStr in above function
- to reduce risk of problems it is better to avoid using variable names that are identical to VBA function names etc
Noted!

You have not given details to allow your problem to be recreated and simply calling the function works fine for me.

When does code fail?
- when the workbook is opened?
- when any code runs?
- only when function DelParens is called?

How are you calling DelParens?

Gah- that's such a level 1 mistake on my part.

The intent of the custom function is to take the text from a particular cell and scan it for parenthesis. If any are found, it trims the parenthethetical text from the stringvalue and outputs the result.

In my workbook, as a dummy example, I have a table with the following columns:

[TABLE="width: 500, align: left"]
<tbody>[TR]
[TD]First[/TD]
[TD]Last[/TD]
[TD]DelParensFirst[/TD]
[TD]DelParensLast[/TD]
[/TR]
[TR]
[TD]Thomas[/TD]
[TD]Smith (Jr)[/TD]
[TD]=delparens(table[First])[/TD]
[TD]=delparens(table[Last])[/TD]
[/TR]
</tbody>[/TABLE]




The output for the last 2 columns would be:
Thomas | Smith

The code fails when the workbook is opened, and closing the error window in the VBA Editor causes an infinite loop of Excel trying to open again, then failing with the same error...

In the VBA editor, the first line is highlighted in yellow:


Code:
[COLOR=#574123][FONT=monospace]Public Function DelParens(ByVal myStr As String) As String
[/FONT][/COLOR]

the function DelParens is only ever called in the table as a formula.

The thing I'm having trouble understanding is why some co-workers computers are fine opening the workbook, but others get this fatal error, and how to fix it.

Thanks again for the assistance!
 
Upvote 0
Is your UDF working correctly for you in a normal Excel workbook not hosted on Sharepoint and just not when hosted on Sharepoint?

I'm guessing UDF = User Defined Function? I'm still kinda new to this stuff :)

The workbook is accessed from the Sharepoint, but due to the contents of the file, it cannot be viewed correctly in a browser, so it must be opened from Excel, from the message prompt below . I don't know if people are downloading the file and opening a local copy...but I know that at least myself and some others open the Sharepoint file in Excel, not on a local file.

Does that help?
6pyaOlb.jpg
[/IMG]
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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