LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default ThisWorkbook.Close crashing Excel (2010)

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


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ThisWorkbook.Close question Robert Crandal Excel Programming 2 January 24th 10 01:38 PM
Excel crashing when trying to close a workbook George J[_3_] Excel Programming 0 September 2nd 09 07:48 PM
Excel crashing intermittently on save or file close - caused by vba? dirt Excel Programming 2 January 6th 05 01:07 AM
ThisWorkbook.close doesn't wokk :( Arnaud.L Excel Programming 9 April 1st 04 08:46 AM


All times are GMT +1. The time now is 08:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"