Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
New install of Office 2010 (after removing Office 2003) [company
decision outside my control] "Document Index.xls" converted and saved as "Document Index.xlsm" Initial testing shows that macro code is doing what I expect, until "ThisWorkbook.Close", which (so far) always results in the Microsoft Excel has encountered a problem and needs to close. We are sorry for the inconvenience. (etc.) crash. I created a new, blank workbook, created a macro with thisworkbook.close, and that worked just fine. I deleted all my macro code, re-compiled, saved the workbook, re-opened it, created a macro with thisworkbook.close, compiled, saved and tested and it works. I deleted the new macro code, pasted the original code (from NotePad), compiled, saved, tested .. and it crashes every time. Any suggestions? The code follows: Option Explicit Const RO As String = "Read Only" Const RW As String = "Read/Write" Const ROFlag As String = "$H$1" Const Description As Long = 3 ' Description Column Const Link As Long = 1 ' Pathname Column = A Const Flag As Long = 8 ' Link Type Column = H Dim SelectionFlag As String ' R/W flag for selected row Dim SelectionLink As String ' Link value for selected row Private Sub Worksheet_BeforeDoubleClick(ByVal _ Target As Range, Cancel As Boolean) ' *** inserted for testing ThisWorkbook.Close Exit Sub ' *** end testing code With Target Select Case .Column Case Description If VarType(.Value) = vbString Then ' assume Link is a valid pathname Cancel = True ' Check flag column for Empty, Read Only, Read/Write or "else" ' Else = hyperlink, not workbook ' Empty uses Read Only Flag cell to open workbook SelectionFlag = .EntireRow.Cells(Flag).Value SelectionLink = .EntireRow.Cells(Link).Value If Not IsEmpty(SelectionFlag) Then Select Case UCase(SelectionFlag) Case UCase(RO) Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=True ' *** this is the branch under test Case UCase(RW) Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=False ' *** Case Else 'hyperlink ActiveWorkbook.FollowHyperlink _ Address:=SelectionLink, _ NewWindow:=True Application.CommandBars("web").Visible = False End Select Else Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=(Range(ROFlag) = RO) End If ' End process link code If Cancel Then ' Cancel = True IFF link followed, ' so close this link document ' *** this is the line that fails ... at least, this is the last line the debugger ' *** single step brought up before the crash pop-up ThisWorkbook.Close ' prompt to save changes ' *** End If ' End Close Workbook code End If ' End test for vbString (assumed link) code End Select ' End test for Link Column End With End Sub ' *** this sub works as expected Private Sub Worksheet_SelectionChange(ByVal _ Target As Range) With Target Select Case .Address Case ROFlag ' Toggle Read Only Control Flag in Worksheet Select Case .Value Case RO .Value = RW Case RW .Value = RO End Select End Select End With End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Status Update:
So far, I have tested BeforeDoubleClick, BeforeRightClick and SelectionChange events. ThisWorkbook.Close works in the SelectionChange event, but crashes in either Click event: Private Sub Worksheet_BeforeRightClick(ByVal _ Target As Range, Cancel As Boolean) ThisWorkbook.Close End Sub always crashes in my testing. Private Sub Worksheet_SelectionChange(ByVal _ Target As Range) ThisWorkbook.Close End Sub always works. "Clif McIrvin" wrote in message ... New install of Office 2010 (after removing Office 2003) [company decision outside my control] "Document Index.xls" converted and saved as "Document Index.xlsm" Initial testing shows that macro code is doing what I expect, until "ThisWorkbook.Close", which (so far) always results in the Microsoft Excel has encountered a problem and needs to close. We are sorry for the inconvenience. (etc.) crash. I created a new, blank workbook, created a macro with thisworkbook.close, and that worked just fine. I deleted all my macro code, re-compiled, saved the workbook, re-opened it, created a macro with thisworkbook.close, compiled, saved and tested and it works. I deleted the new macro code, pasted the original code (from NotePad), compiled, saved, tested .. and it crashes every time. Any suggestions? The code follows: Option Explicit Const RO As String = "Read Only" Const RW As String = "Read/Write" Const ROFlag As String = "$H$1" Const Description As Long = 3 ' Description Column Const Link As Long = 1 ' Pathname Column = A Const Flag As Long = 8 ' Link Type Column = H Dim SelectionFlag As String ' R/W flag for selected row Dim SelectionLink As String ' Link value for selected row Private Sub Worksheet_BeforeDoubleClick(ByVal _ Target As Range, Cancel As Boolean) ' *** inserted for testing ThisWorkbook.Close Exit Sub ' *** end testing code With Target Select Case .Column Case Description If VarType(.Value) = vbString Then ' assume Link is a valid pathname Cancel = True ' Check flag column for Empty, Read Only, Read/Write or "else" ' Else = hyperlink, not workbook ' Empty uses Read Only Flag cell to open workbook SelectionFlag = .EntireRow.Cells(Flag).Value SelectionLink = .EntireRow.Cells(Link).Value If Not IsEmpty(SelectionFlag) Then Select Case UCase(SelectionFlag) Case UCase(RO) Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=True ' *** this is the branch under test Case UCase(RW) Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=False ' *** Case Else 'hyperlink ActiveWorkbook.FollowHyperlink _ Address:=SelectionLink, _ NewWindow:=True Application.CommandBars("web").Visible = False End Select Else Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=(Range(ROFlag) = RO) End If ' End process link code If Cancel Then ' Cancel = True IFF link followed, ' so close this link document ' *** this is the line that fails ... at least, this is the last line the debugger ' *** single step brought up before the crash pop-up ThisWorkbook.Close ' prompt to save changes ' *** End If ' End Close Workbook code End If ' End test for vbString (assumed link) code End Select ' End test for Link Column End With End Sub ' *** this sub works as expected Private Sub Worksheet_SelectionChange(ByVal _ Target As Range) With Target Select Case .Address Case ROFlag ' Toggle Read Only Control Flag in Worksheet Select Case .Value Case RO .Value = RW Case RW .Value = RO End Select End Select End With End Sub -- Clif McIrvin Change nomail.afraid.org to gmail.com to reply by email. (nomail.afraid.org has been set up specifically for use in usenet. Feel free to use it yourself.) |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Private Sub Worksheet_BeforeRightClick(ByVal _
Target As Range, Cancel As Boolean) ThisWorkbook.Close End Sub always crashes in my testing. Same here. If you want a workaround I'd put in a delay, and kill the popup menu: Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) Cancel = True Application.OnTime Now, "CloseMe" End Sub and in a standard module: Sub CloseMe() ThisWorkbook.Close End Sub "Clif McIrvin" wrote in message ... Status Update: So far, I have tested BeforeDoubleClick, BeforeRightClick and SelectionChange events. ThisWorkbook.Close works in the SelectionChange event, but crashes in either Click event: Private Sub Worksheet_BeforeRightClick(ByVal _ Target As Range, Cancel As Boolean) ThisWorkbook.Close End Sub always crashes in my testing. Private Sub Worksheet_SelectionChange(ByVal _ Target As Range) ThisWorkbook.Close End Sub always works. "Clif McIrvin" wrote in message ... New install of Office 2010 (after removing Office 2003) [company decision outside my control] "Document Index.xls" converted and saved as "Document Index.xlsm" Initial testing shows that macro code is doing what I expect, until "ThisWorkbook.Close", which (so far) always results in the Microsoft Excel has encountered a problem and needs to close. We are sorry for the inconvenience. (etc.) crash. I created a new, blank workbook, created a macro with thisworkbook.close, and that worked just fine. I deleted all my macro code, re-compiled, saved the workbook, re-opened it, created a macro with thisworkbook.close, compiled, saved and tested and it works. I deleted the new macro code, pasted the original code (from NotePad), compiled, saved, tested .. and it crashes every time. Any suggestions? The code follows: Option Explicit Const RO As String = "Read Only" Const RW As String = "Read/Write" Const ROFlag As String = "$H$1" Const Description As Long = 3 ' Description Column Const Link As Long = 1 ' Pathname Column = A Const Flag As Long = 8 ' Link Type Column = H Dim SelectionFlag As String ' R/W flag for selected row Dim SelectionLink As String ' Link value for selected row Private Sub Worksheet_BeforeDoubleClick(ByVal _ Target As Range, Cancel As Boolean) ' *** inserted for testing ThisWorkbook.Close Exit Sub ' *** end testing code With Target Select Case .Column Case Description If VarType(.Value) = vbString Then ' assume Link is a valid pathname Cancel = True ' Check flag column for Empty, Read Only, Read/Write or "else" ' Else = hyperlink, not workbook ' Empty uses Read Only Flag cell to open workbook SelectionFlag = .EntireRow.Cells(Flag).Value SelectionLink = .EntireRow.Cells(Link).Value If Not IsEmpty(SelectionFlag) Then Select Case UCase(SelectionFlag) Case UCase(RO) Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=True ' *** this is the branch under test Case UCase(RW) Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=False ' *** Case Else 'hyperlink ActiveWorkbook.FollowHyperlink _ Address:=SelectionLink, _ NewWindow:=True Application.CommandBars("web").Visible = False End Select Else Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=(Range(ROFlag) = RO) End If ' End process link code If Cancel Then ' Cancel = True IFF link followed, ' so close this link document ' *** this is the line that fails ... at least, this is the last line the debugger ' *** single step brought up before the crash pop-up ThisWorkbook.Close ' prompt to save changes ' *** End If ' End Close Workbook code End If ' End test for vbString (assumed link) code End Select ' End test for Link Column End With End Sub ' *** this sub works as expected Private Sub Worksheet_SelectionChange(ByVal _ Target As Range) With Target Select Case .Address Case ROFlag ' Toggle Read Only Control Flag in Worksheet Select Case .Value Case RO .Value = RW Case RW .Value = RO End Select End Select End With End Sub -- Clif McIrvin Change nomail.afraid.org to gmail.com to reply by email. (nomail.afraid.org has been set up specifically for use in usenet. Feel free to use it yourself.) |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Nice workaround. I had never noticed the OnTime method before, Thanks!!
I did get a response from Chad Rothschiller at Microsoft; they are looking into it. Clif "Jim Rech" wrote in message ... Private Sub Worksheet_BeforeRightClick(ByVal _ Target As Range, Cancel As Boolean) ThisWorkbook.Close End Sub always crashes in my testing. Same here. If you want a workaround I'd put in a delay, and kill the popup menu: Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) Cancel = True Application.OnTime Now, "CloseMe" End Sub and in a standard module: Sub CloseMe() ThisWorkbook.Close End Sub "Clif McIrvin" wrote in message ... Status Update: So far, I have tested BeforeDoubleClick, BeforeRightClick and SelectionChange events. ThisWorkbook.Close works in the SelectionChange event, but crashes in either Click event: Private Sub Worksheet_BeforeRightClick(ByVal _ Target As Range, Cancel As Boolean) ThisWorkbook.Close End Sub always crashes in my testing. Private Sub Worksheet_SelectionChange(ByVal _ Target As Range) ThisWorkbook.Close End Sub always works. "Clif McIrvin" wrote in message ... New install of Office 2010 (after removing Office 2003) [company decision outside my control] "Document Index.xls" converted and saved as "Document Index.xlsm" Initial testing shows that macro code is doing what I expect, until "ThisWorkbook.Close", which (so far) always results in the Microsoft Excel has encountered a problem and needs to close. We are sorry for the inconvenience. (etc.) crash. I created a new, blank workbook, created a macro with thisworkbook.close, and that worked just fine. I deleted all my macro code, re-compiled, saved the workbook, re-opened it, created a macro with thisworkbook.close, compiled, saved and tested and it works. I deleted the new macro code, pasted the original code (from NotePad), compiled, saved, tested .. and it crashes every time. Any suggestions? The code follows: Option Explicit Const RO As String = "Read Only" Const RW As String = "Read/Write" Const ROFlag As String = "$H$1" Const Description As Long = 3 ' Description Column Const Link As Long = 1 ' Pathname Column = A Const Flag As Long = 8 ' Link Type Column = H Dim SelectionFlag As String ' R/W flag for selected row Dim SelectionLink As String ' Link value for selected row Private Sub Worksheet_BeforeDoubleClick(ByVal _ Target As Range, Cancel As Boolean) ' *** inserted for testing ThisWorkbook.Close Exit Sub ' *** end testing code With Target Select Case .Column Case Description If VarType(.Value) = vbString Then ' assume Link is a valid pathname Cancel = True ' Check flag column for Empty, Read Only, Read/Write or "else" ' Else = hyperlink, not workbook ' Empty uses Read Only Flag cell to open workbook SelectionFlag = .EntireRow.Cells(Flag).Value SelectionLink = .EntireRow.Cells(Link).Value If Not IsEmpty(SelectionFlag) Then Select Case UCase(SelectionFlag) Case UCase(RO) Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=True ' *** this is the branch under test Case UCase(RW) Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=False ' *** Case Else 'hyperlink ActiveWorkbook.FollowHyperlink _ Address:=SelectionLink, _ NewWindow:=True Application.CommandBars("web").Visible = False End Select Else Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=(Range(ROFlag) = RO) End If ' End process link code If Cancel Then ' Cancel = True IFF link followed, ' so close this link document ' *** this is the line that fails ... at least, this is the last line the debugger ' *** single step brought up before the crash pop-up ThisWorkbook.Close ' prompt to save changes ' *** End If ' End Close Workbook code End If ' End test for vbString (assumed link) code End Select ' End test for Link Column End With End Sub ' *** this sub works as expected Private Sub Worksheet_SelectionChange(ByVal _ Target As Range) With Target Select Case .Address Case ROFlag ' Toggle Read Only Control Flag in Worksheet Select Case .Value Case RO .Value = RW Case RW .Value = RO End Select End Select End With End Sub -- Clif McIrvin Change nomail.afraid.org to gmail.com to reply by email. (nomail.afraid.org has been set up specifically for use in usenet. Feel free to use it yourself.) -- Clif McIrvin Change nomail.afraid.org to gmail.com to reply by email. (nomail.afraid.org has been set up specifically for use in usenet. Feel free to use it yourself.) |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Any news from Chad Rothschiller at Microsoft?
On Tuesday, September 21, 2010 7:42 PM Clif McIrvin wrote: New install of Office 2010 (after removing Office 2003) [company decision outside my control] "Document Index.xls" converted and saved as "Document Index.xlsm" Initial testing shows that macro code is doing what I expect, until "ThisWorkbook.Close", which (so far) always results in the Microsoft Excel has encountered a problem and needs to close. We are sorry for the inconvenience. (etc.) crash. I created a new, blank workbook, created a macro with thisworkbook.close, and that worked just fine. I deleted all my macro code, re-compiled, saved the workbook, re-opened it, created a macro with thisworkbook.close, compiled, saved and tested and it works. I deleted the new macro code, pasted the original code (from NotePad), compiled, saved, tested .. and it crashes every time. Any suggestions? The code follows: Option Explicit Const RO As String = "Read Only" Const RW As String = "Read/Write" Const ROFlag As String = "$H$1" Const Description As Long = 3 ' Description Column Const Link As Long = 1 ' Pathname Column = A Const Flag As Long = 8 ' Link Type Column = H Dim SelectionFlag As String ' R/W flag for selected row Dim SelectionLink As String ' Link value for selected row Private Sub Worksheet_BeforeDoubleClick(ByVal _ Target As Range, Cancel As Boolean) ' *** inserted for testing ThisWorkbook.Close Exit Sub ' *** end testing code With Target Select Case .Column Case Description If VarType(.Value) = vbString Then ' assume Link is a valid pathname Cancel = True ' Check flag column for Empty, Read Only, Read/Write or "else" ' Else = hyperlink, not workbook ' Empty uses Read Only Flag cell to open workbook SelectionFlag = .EntireRow.Cells(Flag).Value SelectionLink = .EntireRow.Cells(Link).Value If Not IsEmpty(SelectionFlag) Then Select Case UCase(SelectionFlag) Case UCase(RO) Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=True ' *** this is the branch under test Case UCase(RW) Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=False ' *** Case Else 'hyperlink ActiveWorkbook.FollowHyperlink _ Address:=SelectionLink, _ NewWindow:=True Application.CommandBars("web").Visible = False End Select Else Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=(Range(ROFlag) = RO) End If ' End process link code If Cancel Then ' Cancel = True IFF link followed, ' so close this link document ' *** this is the line that fails ... at least, this is the last line the debugger ' *** single step brought up before the crash pop-up ThisWorkbook.Close ' prompt to save changes ' *** End If ' End Close Workbook code End If ' End test for vbString (assumed link) code End Select ' End test for Link Column End With End Sub ' *** this sub works as expected Private Sub Worksheet_SelectionChange(ByVal _ Target As Range) With Target Select Case .Address Case ROFlag ' Toggle Read Only Control Flag in Worksheet Select Case .Value Case RO .Value = RW Case RW .Value = RO End Select End Select End With End Sub On Wednesday, September 22, 2010 12:36 PM Clif McIrvin wrote: Status Update: So far, I have tested BeforeDoubleClick, BeforeRightClick and SelectionChange events. ThisWorkbook.Close works in the SelectionChange event, but crashes in either Click event: Private Sub Worksheet_BeforeRightClick(ByVal _ Target As Range, Cancel As Boolean) ThisWorkbook.Close End Sub always crashes in my testing. Private Sub Worksheet_SelectionChange(ByVal _ Target As Range) ThisWorkbook.Close End Sub always works. -- Clif McIrvin Change nomail.afraid.org to gmail.com to reply by email. (nomail.afraid.org has been set up specifically for use in usenet. Feel free to use it yourself.) On Thursday, September 23, 2010 6:54 AM Jim Rech wrote: Target As Range, Cancel As Boolean) ThisWorkbook.Close End Sub Same here. If you want a workaround I'd put in a delay, and kill the popup menu: Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) Cancel = True Application.OnTime Now, "CloseMe" End Sub and in a standard module: Sub CloseMe() ThisWorkbook.Close End Sub On Thursday, September 23, 2010 9:55 AM Clif McIrvin wrote: Nice workaround. I had never noticed the OnTime method before, Thanks!! I did get a response from Chad Rothschiller at Microsoft; they are looking into it. Clif -- Clif McIrvin Change nomail.afraid.org to gmail.com to reply by email. (nomail.afraid.org has been set up specifically for use in usenet. Feel free to use it yourself.) Submitted via EggHeadCafe - Software Developer Portal of Choice SharePoint Create List Add/Edit Form Web Part With Custom Toolbar and Attachments Option http://www.eggheadcafe.com/tutorials...ts-option.aspx |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Michel D" wrote in message
... Any news from Chad Rothschiller at Microsoft? Well, yes and no. Turns out this bug goes back as far as Excel 2003 at least, maybe more, and we haven't fixed it yet (probably because we're not sure anyone cares for "real" reasons). I'll inquire and see if I can learn if they assigned a tracking ID or anything; I'm simply using the workaround suggested by Jim Rech (below, also ) of using Application.OnTime to move the ThisWorkbook.Close command out of the running procedure. I have encountered two cases where Excel crashes, and Jim's workaround succeeds: -- DoubleClick or RightClick event code executing ThisWorkbook.Close -- DoubleClick or RightClick event code executing sheetObject.Activate, where the sheetObject is in a different workbook. I found it interesting that though they said the bug exists in xl2003 my code ran fine then. Clif On Tuesday, September 21, 2010 7:42 PM Clif McIrvin wrote: <snip Initial testing shows that macro code is doing what I expect, until "ThisWorkbook.Close", which (so far) always results in the Microsoft Excel has encountered a problem and needs to close. We are sorry for the inconvenience. (etc.) <snip On Thursday, September 23, 2010 6:54 AM Jim Rech wrote: Target As Range, Cancel As Boolean) ThisWorkbook.Close End Sub Same here. If you want a workaround I'd put in a delay, and kill the popup menu: Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) Cancel = True Application.OnTime Now, "CloseMe" End Sub and in a standard module: Sub CloseMe() ThisWorkbook.Close End Sub -- Clif McIrvin Change nomail.afraid.org to gmail.com to reply by email. (nomail.afraid.org has been set up specifically for use in usenet. Feel free to use it yourself.) |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Clif,
If my code is... Sub byebye() Activeworkbook.close False End Sub And that I have an Option button on a sheet that is linked to this macro, I don't understand how to integrate this workaround into my workbbook using the OnTime Now option. Also, I need to point out that I did some testing and found that if I link the code to a standard grey macro button, It works fine BUT just one time. The second time I try to run the code it crashes. NOTE: My workbook in question was created in EXCEL XP. and now with EXCEL 2010, It crashes. Regards, Michel On Tuesday, September 21, 2010 7:42 PM Clif McIrvin wrote: New install of Office 2010 (after removing Office 2003) [company decision outside my control] "Document Index.xls" converted and saved as "Document Index.xlsm" Initial testing shows that macro code is doing what I expect, until "ThisWorkbook.Close", which (so far) always results in the Microsoft Excel has encountered a problem and needs to close. We are sorry for the inconvenience. (etc.) crash. I created a new, blank workbook, created a macro with thisworkbook.close, and that worked just fine. I deleted all my macro code, re-compiled, saved the workbook, re-opened it, created a macro with thisworkbook.close, compiled, saved and tested and it works. I deleted the new macro code, pasted the original code (from NotePad), compiled, saved, tested .. and it crashes every time. Any suggestions? The code follows: Option Explicit Const RO As String = "Read Only" Const RW As String = "Read/Write" Const ROFlag As String = "$H$1" Const Description As Long = 3 ' Description Column Const Link As Long = 1 ' Pathname Column = A Const Flag As Long = 8 ' Link Type Column = H Dim SelectionFlag As String ' R/W flag for selected row Dim SelectionLink As String ' Link value for selected row Private Sub Worksheet_BeforeDoubleClick(ByVal _ Target As Range, Cancel As Boolean) ' *** inserted for testing ThisWorkbook.Close Exit Sub ' *** end testing code With Target Select Case .Column Case Description If VarType(.Value) = vbString Then ' assume Link is a valid pathname Cancel = True ' Check flag column for Empty, Read Only, Read/Write or "else" ' Else = hyperlink, not workbook ' Empty uses Read Only Flag cell to open workbook SelectionFlag = .EntireRow.Cells(Flag).Value SelectionLink = .EntireRow.Cells(Link).Value If Not IsEmpty(SelectionFlag) Then Select Case UCase(SelectionFlag) Case UCase(RO) Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=True ' *** this is the branch under test Case UCase(RW) Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=False ' *** Case Else 'hyperlink ActiveWorkbook.FollowHyperlink _ Address:=SelectionLink, _ NewWindow:=True Application.CommandBars("web").Visible = False End Select Else Workbooks.Open Filename:=SelectionLink, _ ReadOnly:=(Range(ROFlag) = RO) End If ' End process link code If Cancel Then ' Cancel = True IFF link followed, ' so close this link document ' *** this is the line that fails ... at least, this is the last line the debugger ' *** single step brought up before the crash pop-up ThisWorkbook.Close ' prompt to save changes ' *** End If ' End Close Workbook code End If ' End test for vbString (assumed link) code End Select ' End test for Link Column End With End Sub ' *** this sub works as expected Private Sub Worksheet_SelectionChange(ByVal _ Target As Range) With Target Select Case .Address Case ROFlag ' Toggle Read Only Control Flag in Worksheet Select Case .Value Case RO .Value = RW Case RW .Value = RO End Select End Select End With End Sub On Wednesday, September 22, 2010 12:36 PM Clif McIrvin wrote: Status Update: So far, I have tested BeforeDoubleClick, BeforeRightClick and SelectionChange events. ThisWorkbook.Close works in the SelectionChange event, but crashes in either Click event: Private Sub Worksheet_BeforeRightClick(ByVal _ Target As Range, Cancel As Boolean) ThisWorkbook.Close End Sub always crashes in my testing. Private Sub Worksheet_SelectionChange(ByVal _ Target As Range) ThisWorkbook.Close End Sub always works. -- Clif McIrvin Change nomail.afraid.org to gmail.com to reply by email. (nomail.afraid.org has been set up specifically for use in usenet. Feel free to use it yourself.) On Thursday, September 23, 2010 6:54 AM Jim Rech wrote: Target As Range, Cancel As Boolean) ThisWorkbook.Close End Sub Same here. If you want a workaround I'd put in a delay, and kill the popup menu: Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) Cancel = True Application.OnTime Now, "CloseMe" End Sub and in a standard module: Sub CloseMe() ThisWorkbook.Close End Sub On Thursday, September 23, 2010 9:55 AM Clif McIrvin wrote: Nice workaround. I had never noticed the OnTime method before, Thanks!! I did get a response from Chad Rothschiller at Microsoft; they are looking into it. Clif -- Clif McIrvin Change nomail.afraid.org to gmail.com to reply by email. (nomail.afraid.org has been set up specifically for use in usenet. Feel free to use it yourself.) On Wednesday, October 13, 2010 8:22 PM Michel D wrote: Any news from Chad Rothschiller at Microsoft? Submitted via EggHeadCafe - Software Developer Portal of Choice ASP.NET MaskedTextBox Custom Control http://www.eggheadcafe.com/tutorials...m-control.aspx |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Michel D" wrote in message
... Hi Clif, If my code is... Sub byebye() Activeworkbook.close False End Sub And that I have an Option button on a sheet that is linked to this macro, I don't understand how to integrate this workaround into my workbbook using the OnTime Now option. Did you see my reply on 10/16 evening explaining the mechanism to integrate the workaround? Also, I need to point out that I did some testing and found that if I link the code to a standard grey macro button, It works fine BUT just one time. The second time I try to run the code it crashes. It would help us help you if you could explain more about what you are wishing to accomplish. Your explanation so far gives us a bit about "what" you are doing but doesn't give any insight about "why". It may be that a different approach would serve you better. For instance: I have a workbook that is nothing more than a list of other workbooks that I occasionally use. I found that it works well for me to create a toolbar macro to open my cross-refrence workbook, then double-click on the workbook I want to open rather than using Windows Explorer, or File Open. This cross-reference workbook contains Double-Click event code to open the workbook of interest, then close itself. So .. I have code running within a workbook that opens a different workbook, then closes itself. From your description (when working in workbook A the user opens workbook B, then later clicks a button to close workbook B) I wonder if Workbooks("b.xls").Close False (or prehaps:) Dim strBookName as String strBookName = "b.xls" Workbooks(xtrBookName).Close False would work better for you. NOTE: My workbook in question was created in EXCEL XP. and now with EXCEL 2010, It crashes. For me, it didn't matter if I used a workbook created in xl2003 or xl2010, the code worked fine in xl2003 and always crashed in xl2010. HTH! -- Clif McIrvin Change nomail.afraid.org to gmail.com to reply by email. (nomail.afraid.org has been set up specifically for use in usenet. Feel free to use it yourself.) |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
ThisWorkbook.Close question | Excel Programming | |||
Excel crashing when trying to close a workbook | Excel Programming | |||
Excel crashing intermittently on save or file close - caused by vba? | Excel Programming | |||
ThisWorkbook.close doesn't wokk :( | Excel Programming |