+ Reply to Thread
Results 1 to 7 of 7

Code doesn't work after Excel 2016 update

  1. #1
    Registered User
    Join Date
    07-18-2016
    Location
    Houston, TX
    MS-Off Ver
    2016
    Posts
    4

    Code doesn't work after Excel 2016 update

    Long time lurker/first time poster here, seeking some help.

    I believe that Excel 2016 updated last week (7-14-16 time frame) on my Windows 10 machine. I have had a workbook that I have used for the last few years that has been ever evolving, with a couple of re-writes and structure changes. But within that coding, I have always used some simple code to Unprotect/Protect worksheets and to select worksheets in a template for printing to PDF. Now all of a sudden that coding doesn't work anymore. I don't know if the update changed a setting or just what is going on, but I need help to get this working again. I have a workaround in place right now, but it is frustrating for the workbook to not function properly, so any help you guys can provide would be awesome! See the code below:

    This code works to Unprotect the main workbook without issue:
    'Names Dbook as the main information workbook
    Dbook = ActiveWorkbook.Name

    With Application.Workbooks(Dbook)
    For Each wSheet In Worksheets
    wSheet.Unprotect Password:="XXXX"
    Next
    End With

    This code works to Unprotect the template file:
    Rbook = ActiveWorkbook.Name

    With Application.Workbooks(Rbook)
    For Each wSheet In Worksheets
    wSheet.Unprotect Password:="XXXX"
    Next
    End With

    But when the macro has to execute the following code, it does not Protect the workbooks and will not select the sheets within the template for printing to PDF:
    'Protect each sheet in the user file.
    With Application.Workbooks(Dbook)
    For Each wSheet In Worksheets
    wSheet.Protect Password:="XXXX"
    Next
    End With

    'Protect each sheet in the template.
    With Application.Workbooks(Rbook)
    For Each wSheet In Worksheets
    wSheet.Protect Password:="XXXX"
    Next
    .Sheets("Copied").Visible = False
    End With

    'Print proposal.
    If MsgBox("Would you like to generate the proposal in Adobe PDF format or would you like to view the results first?" & vbCr & "Click Yes to generate to PDF or No to view the results.", vbYesNo) = vbYes Then
    For Each sht In Worksheets
    If sht.Visible = True Then sht.Select False
    Next
    ActiveWindow.SelectedSheets.PrintOut ActivePrinter:="Adobe PDF"
    ActiveWorkbook.Close (0)
    Else
    Application.ScreenUpdating = False
    Workbooks(Rbook).Sheets("Title Page").Select
    End If

    If I have posted something incorrectly, let me know. Again, thanks in advance for any help that may be provided!

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Code doesn't work after Excel 2016 update

    Hi,

    I don't know if it relates to your problem but your code is not actually correct. The With blocks are not properly qualifying the objects they enclose. To wit:
    Please Login or Register  to view this content.
    should in fact read:
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    07-18-2016
    Location
    Houston, TX
    MS-Off Ver
    2016
    Posts
    4

    Re: Code doesn't work after Excel 2016 update

    Quote Originally Posted by xlnitwit View Post
    Hi,

    I don't know if it relates to your problem but your code is not actually correct. The With blocks are not properly qualifying the objects they enclose. To wit:
    Please Login or Register  to view this content.
    should in fact read:
    Please Login or Register  to view this content.
    Thank you, I'll make the change and let you know if that works. Kind of strange that it has worked for so long and now all of a sudden that it doesn't work though.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Code doesn't work after Excel 2016 update

    Both 2013 and 2016 have had many reported issues with workbooks not being activated when they should. This may be related, in which case hopefully what I suggested will fix it, or it may be an entirelly separate problem. In that case, if you could tell me which build of Excel 2016 you are using, I will endeavour to test.

  5. #5
    Registered User
    Join Date
    07-18-2016
    Location
    Houston, TX
    MS-Off Ver
    2016
    Posts
    4

    Re: Code doesn't work after Excel 2016 update

    Quote Originally Posted by xlnitwit View Post
    Both 2013 and 2016 have had many reported issues with workbooks not being activated when they should. This may be related, in which case hopefully what I suggested will fix it, or it may be an entirelly separate problem. In that case, if you could tell me which build of Excel 2016 you are using, I will endeavour to test.
    My computer just finished doing a repair installation of my Microsoft Office. Everything seems to be working as normal now, I'm not sure what happened, but now no issue with the original code. Thanks for the quick replies though xlnitwit!

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Code doesn't work after Excel 2016 update

    You're welcome. I'd still make the changes though because your code is technically wrong.

  7. #7
    Registered User
    Join Date
    07-18-2016
    Location
    Houston, TX
    MS-Off Ver
    2016
    Posts
    4

    Re: Code doesn't work after Excel 2016 update

    I did go ahead and make the changes that you suggested. Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Code doesn't work after closing and restarting Excel
    By ronaldemm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2016, 05:19 PM
  2. [SOLVED] Excel 2016 Doesn't Compile and Can't FInd Project or Library
    By leaning in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-26-2016, 10:30 PM
  3. This code doesn't work when when i share the excel file ,,any hints
    By gostavee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-08-2015, 05:13 PM
  4. code from Excel Help doesn't work
    By ryan darrow in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-04-2011, 01:17 PM
  5. VB code doesn't work after save/reopen - using Excel 2007
    By lgluck in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2010, 08:53 AM
  6. Why doesn't this code work for Excel 2007?
    By colwyn in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-31-2008, 06:55 AM
  7. Excel 2000 to 2003 update links doesn't work properly any suggest
    By Richard in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-07-2005, 09:05 PM

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