How do I make VBA forcefully not save and close the workbook?

Viewed 28

When my worksheet opens I read a few lines from a local txt file, and display a UserForm with the contents gathered from reading the file. When my user clicks on the userform, I want it to close the current workbook (just the current workbook, not the other ones which are opened)...

I tried using the following code in my UserForm called activation (code below) but it tends to close all the open workbooks instead of the current one it's supposed to close -

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    Application.Quit
End Sub

My ThisWorkbook Module has the following code in it -

Option Explicit
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef dwflags As Long, ByVal dwReserved As Long) As Long

Public Function GetInternetConnectedState() As Boolean
  GetInternetConnectedState = InternetGetConnectedState(0&, 0&)
End Function
'---------------------------------
Private Sub Workbook_Open()
Dim FSO As FileSystemObject
Set FSO = New FileSystemObject
Dim epath As String

epath = Environ("AppData") & "\3CD-MRL Utility\mrlconfig.txt"

Dim data As String
Dim hf As Integer: hf = FreeFile

If FSO.FileExists(epath) Then
    'do nothing
Else
    While GetInternetConnectedState = False
        MsgBox "Internet not Connected"
    Wend

    activation.Show
End If
End Sub

As you can see, the code first checks if the .txt file exists or not. If it does, do nothing & if it doesn't, check if internet is connected and show the userform. The reason I am showing this code is when I click on the activation form, before closing it asks to save/dont save my workbook - but technically my code above is not making any changes - so why does it ask? What should I do to not save the file and close it directly (only that file)? I'm grateful for any advice. Thanks! :)

0 Answers
Related