Kenny Bones
Kenny Bones

Reputation: 5139

Vba - On error doesn't work? Reading registry value

this is strange, I've got a macro with an array containing several registry keys. And I want to insert the values of these into predefined bookmarks in a Word document.

This works great if the key is there, but if it isn't, I want the code to skip that and continue trying the next one in the array.

I've got the code that looks like this:

sVerdi = objShell.RegRead(regPath & "\" & Felter(iTeller))

This line of code returns the value of the registry key, dictated by the first in the array. But, if the registry key isn't in the registry, I naturally get an error:

Run-time error '-2147024894(80070002)':

Unable to open registry key
"HKEY_CURRENT_USER\Blablabla" for reading

Now, this is logical, but if I throw in an "On error GoTo 0", then it just ignores that line. I can't figure it out, I go step by step through each array the error keeps coming.

Any idea?

Upvotes: 0

Views: 1477

Answers (1)

AakashM
AakashM

Reputation: 63378

When you say 'it just ignores that line, do you mean the On Error GoTo 0 ? On Error GoTo 0 doesn't mean ignore errors: it means 'restore default error handling'. Did you mean to use On Error Resume Next ?

Upvotes: 1

Related Questions