View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
ASCO IS Help ASCO IS Help is offline
external usenet poster
 
Posts: 1
Default run-time error '91' - Close Button Error

Sub CloseMacro()
If IntState = "ON" Then
CancelDone = False
If Application.ActiveWindow.WindowNumber = 1 Then
DocIsReadOnly = ActiveWorkbook.ReadOnly
StoredId = GetDocumentId()
If StoredId < "" Then 'End-Retrieve the open document
DocId = StoredId
DocWasSaved = ActiveWorkbook.Saved
If Not (DocWasSaved) Then
ret = GWGetDocInfo(DocId, GW_NAME, DocInfoStr, 255)
If ret < GW_OK Or DocInfoStr = "" Then
DocInfoStr = DocId
End If
MsgStr = ClosePromptStr + DocInfoStr + "'?"
Style = vbYesNoCancel + vbQuestion
ret = MsgBox(MsgStr, Style, "Microsoft Excel")
Select Case ret
Case vbYes
If DocIsReadOnly Then 'create a new profile for
the document
SaveNewDoc
Else
ActiveWorkbook.Save
End If
Case vbNo
ActiveWorkbook.Saved = True
Case vbCancel
CancelDone = True
GoTo NeverMind
End Select
End If
Application.ActiveWindow.Close
ret = GWCloseDoc(StoredId, 0, 0)
NeverMind:
Else 'If there is no DocId, check if the document has a name
If ActiveWorkbook.Path = "" Or DocIsReadOnly Then 'If the
doc is unnamed
SaveNewDoc
Else 'Just close the Named, Non-profiled document.
Application.ActiveWindow.Close
End If
End If
Else 'this is not the first window for the workbook
Application.ActiveWindow.Close
End If