+ Reply to Thread
Results 1 to 10 of 10

Macro to find and replace links in hidden worksheets

  1. #1
    Registered User
    Join Date
    08-19-2012
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2010
    Posts
    62

    Macro to find and replace links in hidden worksheets

    Hello,
    I'd really appreciate if someone can help me to fix my code so that it works.

    Here's a summary of what the macro is supposed to do:
    1. It unhides all sheets
    2. It unprotects all sheets
    3. It unprotects the workbook
    4. If there any errors during any time, it goes to an error handler so that the workbook and sheets aren't left unprotected or certain sheets unhidden.

    5. It does several find and replaces to fix links within cells of the entire workbook and all sheets.

    6. It re-hides all sheets
    7. It re-protects all sheets
    8. It re-protects the workbook

    Here is my code, please help if you can...Thank you very much!!

    Please Login or Register  to view this content.
    Last edited by lottidotti; 02-09-2013 at 11:59 AM. Reason: updated code

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,342

    Re: Macro to find and replace links in hidden worksheets

    help me to fix my code so that it works

    Can you be more specific about what doesn't work, or what doesn't work as you expect it to and, when it "doesn't work", what does it do? Error message? What?

    And I would suggest that you post a sample workbook so that your code, and any amendments, can be tested.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    08-19-2012
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Macro to find and replace links in hidden worksheets

    Quote Originally Posted by TMShucks View Post
    Can you be more specific about what doesn't work, or what doesn't work ...
    Sorry, I'll be more specific.

    An error message comes up saying:
    "Run-time error '1004': Unable to set the Visible property of the Worksheet class"


    The error comes up for the first line of ErrHandl:
    for this line:

    Please Login or Register  to view this content.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,342

    Re: Macro to find and replace links in hidden worksheets

    You must have at least one sheet visible. That error is what you get when you try to hide the last visible sheet.


    Regards, TMS

  5. #5
    Registered User
    Join Date
    08-19-2012
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Macro to find and replace links in hidden worksheets

    Quote Originally Posted by TMShucks View Post
    You must have at least one sheet visible. That error is what you get when you try to hide the last visible sheet.
    I still have 11 other sheets in the workbook though that I haven't hidden.
    So I'm not sure why that error would come up? Do you have any idea?

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,342

    Re: Macro to find and replace links in hidden worksheets

    Well, you can see your workbook, and you can run your code and you can see it fail.

    I can see the code, but I can't test it because I have no data.

    On the basis of what you have reported so far, I have guessed at what the problem might be.

    Do you have any idea?

    No. Back in my first reply, I suggested you post a sample workbook with the code and which demonstrates the problem. With that, we'll have a much better chance of determining the cause of the error.

    Up to you.

    Regards, TMS

  7. #7
    Registered User
    Join Date
    08-19-2012
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Macro to find and replace links in hidden worksheets

    Quote Originally Posted by TMShucks View Post
    Well, you can see your workbook, and you can run your code and you can see it fail.

    I can see the code, but I can't test it because I have no data.

    On the basis of what you have reported so far, I have guessed at what the problem might be.
    ...
    TMShucks, thanks for your help so far, I will create a sample spreadsheet, but it will take me a little time because there is a good bit of private information that I'll have to remove.

  8. #8
    Registered User
    Join Date
    08-19-2012
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Macro to find and replace links in hidden worksheets

    Quote Originally Posted by TMShucks View Post
    ...Back in my first reply, I suggested you post a sample workbook with the code and which demonstrates the problem. With that, we'll have a much better chance of determining the cause of the error.

    Up to you.

    Regards, TMS
    Here is my sample worksheet.
    Fix Replace Links Test Sample.xlsm
    The password to unprotect workbook and sheets is "ABC".

    The macro seems to run ok and it seems to do the job with finding and replacing, it even re-hides the sheets that I want it to, but it keeps coming up with that error on the first line of the Error Handler:
    Please Login or Register  to view this content.
    Thanks for your help!

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,342

    Re: Macro to find and replace links in hidden worksheets

    Don't just drop into the Error Handler. You need an Exit Sub immediately before it. You only go to the Error Handler if there is an error, you shouldn't just drop through it unless it is designed to be the "normal" exit routine.

    Please Login or Register  to view this content.

    The problem is actually because you have protected the workbook structure before you drop into the error handler.


    Regards, TMS

  10. #10
    Registered User
    Join Date
    08-19-2012
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Macro to find and replace links in hidden worksheets

    Quote Originally Posted by TMShucks View Post
    Don't just drop into the Error Handler. You need an Exit Sub immediately before it. You only go to the Error Handler if there is an error, you shouldn't just drop through it unless it is designed to be the "normal" exit routine.
    ...
    Thank you TMShucks, I didn't realize that.
    Also, are my statements with "Application.EnableCancelKey"
    in the right place and done correctly?

    I want to make sure that the user can't stop or escape in the middle of the code while parts are unprotected or while specific sheets are unhidden.

    It should make sure that everything is protected and the proper sheets are hidden before it will escape from the code.

    Thanks for all your help TMShucks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1