Excel: disable "Error in loading DLL" message - excel

I am building a data validation system (to check entries in cells) that is referring to a dynamically built named range. Sometimes the range does not exist and I have the "Error in loading DLL message".. is there a way to disable it? Thanks.

If you don't have to know wether the error was triggered then try this:
On Error Resume Next
<code accessing the named range>
On Error Goto 0
If you need a way to check wether the error would have been raised:
Dim flag as Boolean
flag = False
On Error Resume Next
<code accessing the named range>
flag = True
On Error Goto 0
Flag will only become True if the critical code has been executed successfully
I know its dirty but so is VBA ;o)

Related

Different computers handling "On Error Resume Next" differently?

I have the following code:
Sub test()
On Error GoTo Label
Debug.Print 1 / 0
Exit Sub
Label:
MsgBox "Infinity!"
End Sub
If I run this code on my laptop, I get "Infinity", as I expected. However... When I run it on my desktop, excel throws an error message Runtime error 11 ... Division by zero
Has anyone ever experienced this before? It's almost like my Excel desktop client has just 'forgotton' how to handle errors...
Most likely this is due to different settings in your VB editor under
Tools>>Options>>General>>Error Trapping
If set to "Break on all errors" then that's what it does...

Unable to execute kill function VBA - Run-time error '13'

I'm unable to perform the Kill function using Visual Basic in Excel. When I run the code to Kill, I get
"Run-time error '13' Type mismatch'
Does anybody have any ideas? I've tried
Kill("pathname")
and
Kill "pathname"
I've tried different filetypes in various locations and always end up getting the same error.
Edit- I've now reverted to attempting the simplest of Macros and I still get the error instantly:
Sub KillFile()
Dim filetokill As String
filetokill = "C:\Users\thomas.bennett\Desktop\test.txt"
VBA.Kill filetokill
End Sub
Both of these should work, to delete a file from for instance, your desktop.
Sub killfile1()
Dim filetokill As String
filetokill = "C:\Users\yourusername\Desktop\test.txt"
Kill filetokill
End Sub
Sub killfile2()
Kill "C:\Users\yourusername\Desktop\test.txt"
End Sub
I've had an idea though.. you haven't created a FUNCTION or SUB called Kill have you? I just created one and it didn't disallow it:
Function kill(filename As Integer)
End Function
If this is present, I get the exact same error (13) as you when running either of my example macros. Check your code for other uses of Kill.

excel vba error handling

I'm having trouble with an error handling in VBA excel.
Basicaly, I have a situation where I'm dealing with multiple errors within same error handling block.
To make things really simple let's just say:
Sub some_function ()
On Error go to step1
step2:
some code which triggers an error
Exit Sub
step1:
Okay, so far so good.
Problem is, that in this block of code can also occur an error
with the same Err.Number but I have to deal with him on other way
which is not specified in this block of code.
go to step 2
End sub
I'm using SAP session to connect to SAPgui and I cannot predict which error will occur. If I can catch an error within error handling block of code I can solve this situation.
So basicaly I'm blind foilded. If an error occurs I try to do some other things and if it works OK, but if an error occurs second time (within error handling block) it will throw me an error.
Is there any walkaround?
UPDATE:
just thinking out loud.
If I use On Error Resume next statement and do as following:
On Error Resume next
some code,
line of code that could trigger an error
if Err.Number <> 0 Then
try to handle an error
Err.Clear
End if
line of code that could also trigger an error
If Err.Number <> 0 Then
Try to handle an error
Err.Clear
End If
Would that be OK? or is there any better solution?
Is it possible to use Resume next statement within the procedure in only a certain block of code? Let's just say we have a procedure with 20 lines, and I would like to use Resume Next statement between 10th and 15th line.. Is it possible to enable and disable Resume next statement, or on Error line?
How about putting the code in step 2 into a separate procedure? There, you can do separate error handling with a new on error goto statement.

Activeworkbook - error 91 - Object Variable or with block variable not set - in Workbook_open

I have seen several questions relating to Object variable not set when using Activeworkbook, but none for my particular scenario. I use some code in workbook_open that tests a condition to decide if the user should be shown a form
If Len(ActiveWorkbook.Names("DCStype_Selected").RefersToRange.Value) = 0 Then
This works fine for most users 99% of the time. However some users have reported error 91 - Object Variable or with block variable not set, and it is on the activeworkbook line.
I believe I have tracked the scenario where this happens and it is always for users who do not have my excel workbook in a trusted location, and so are prompted to enable macros and this error occurs when they click the "enable" button.
Once I have talked them through setting a folder as a trusted location, and moving the workbook to that folder, this issue does not occur.
Could anyone tell me a more defensive way to code my line, so that it works regardless of a users security settings?
Could some one explain why this error only occurs in this specific scenario?
I would set ActiveWorkbook.Names("DCStype_Selected").RefersToRange.Value as a variable and on error
either set a message box to tell them to move the file to a trusted folder
or set the variable to 0 to avert further damage and debug mode
Sub ert()
On Error GoTo Err
... 'your code
If False Then
Err:
... 'MsgBox or setting the var to 0
End If
End Sub
A little late to the party but I had the exact same problem... eventually got around it like this:
Dim wBook As Workbook
Do While wBook Is Nothing
Set wBook = ActiveWorkbook
DoEvents
' Prob. put a counter in here to prevent infinite looping...
Loop

VBA Error Handling not working in Excel

I have not had much experience with VBA, but I sometimes use it at work. Recently, I have encountered a problem that shouldn't happen, and that neither my boss nor myself can figure out.
Basically, the issue is that the Application property DisplayAlerts is set to True by default and can't be changed for some reason. Possibly related is that when I hit an error, it always display the End|Debug|Help alert and never hits the applied error handling.
I am running 64-bit Office 2010 on a 64-bit Windows 7 machine. However, I do not believe it to be a platform issue, as I have tested on multiple different platforms, operating systems and software permutations and no other machine has this error; just mine.
I have created some sample code in case anyone has encountered this before or has any ideas. The only thing I can think of, is that I have something installed on my machine that is causing this. But after a program purge and many restarts, I am no closer to deciphering what it might be.
Public Sub TestErrorHandler()
' Suppress alerts
Application.DisplayAlerts = False
Dim strArray(1) As String
strArray(0) = "Hello"
strArray(1) = "World"
' Set up error handler
On Error GoTo ErrHandler
For i = 0 To 3
MsgBox strArray(i)
Next
' Strip the error handler
On Error GoTo 0
' Unsuppress alerts
Application.DisplayAlerts = True
Exit Sub
ErrHandler:
MsgBox "Error: " & Err.Description
Resume Next
End Sub
The error is thrown on the third enumeration of the for-loop (as it should). The type of the error is irrelevant, what is relevant is that I get the error and never hit the error handler.
Any suggestions or help on this would be greatly appreciated.
Many thanks!
Press ALT + F11 from within Excel to reach VBA editor.
Goto Tools menu -> Options item -> General tab.
Set the error trapping to "Break on unhandled errors"
(source: microsoft.com)

Resources