0

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
  • Why was this tagged as "vb.net"? It doesn't seem to be a vb.net question. Jun 3, 2009 at 15:18

1 Answer 1

1

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 ?

2
  • 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? Jun 3, 2009 at 10:17
  • 1
    Just found the answer, I needed to reset the string where the last registry value from the array was stored. Thanx! :) Jun 3, 2009 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.