+ Reply to Thread
Results 1 to 2 of 2

unable to close password protected workbook using VBA code in another workbook

  1. #1
    Registered User
    Join Date
    10-02-2012
    Location
    england
    MS-Off Ver
    Excel 2003
    Posts
    2

    unable to close password protected workbook using VBA code in another workbook

    I've designed some vba coding to work from workbook1, this opens a workbook (call it workbook2), copy all of the data from the sheets in the workbook2 to the workbook1 and then close workbook2.

    This code was working perfectly, until now! One of the worksheets that need to be opened have now been password protected, which I can't get access to due to the nature of the form, they've sent me the VBA coding in the forms, which is relatively generic.

    Now the problem is when I try to run the code Workbooks(customerWorkbook.name).Close savechanges:=False I get the runtime error 1004 "application-defined or object-defined error", I'm 99% sure it's because the file is password protected as the non protected, macro free form they also sent me runs fine.

    here is the code:

    Please Login or Register  to view this content.
    As you can see I tried activating the sheet and closing it that way, but gives the same error message, my question is how can I force close a protected workbook without it throwing an error message??

    The code works fine if I omit the close section of the code, but it's vital the workbook is actually closed and numerous ones will be opened - it's also strange that I can close the workbook without any problems by pressing the X close, or going to file-close on the workbook, just the VBA code isn't!

    I've been banging my head at work for months to wrinkle out all of the problems, and now they've thrown this spanner into the works by password protecting it Any help would be greatly appreciated!!

    Thanks,

    Omar!

  2. #2
    Registered User
    Join Date
    10-02-2012
    Location
    england
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: unable to close password protected workbook using VBA code in another workbook

    Sorry managed to fix it by using Application.DisplayAlerts = False and Application.DisplayAlerts = true, strange it does actually close it too!

+ 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