views:

544

answers:

1

Hi, 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?

+1  A: 

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 ?

AakashM
It ignores that line, meaning, it just continues and I get the error message. I want it to skip everything if it encounteres an error, continuing on the next entry in the awway. Hence, NOT raising an error at all. If I use On Error Resume Next, it does the same thing, except doesn't raise an error message. But that means that the string where I store the values from the registry entries, doesn't get updated. Therefore, the same value is put in the next bookmark. I need the code to restart if it encounteres an error. Perhaps, you need to see the whole code?
Kenny Bones
Just found the answer, I needed to reset the string where the last registry value from the array was stored. Thanx! :)
Kenny Bones