【发布时间】:2016-12-24 11:13:04
【问题描述】:
我正在编写一个窗口,要求提示用户保存文件。它关闭并询问他们是否要覆盖文件,除非我按下取消它仍然卡在 while 循环中。有谁知道取消/关闭窗口的代码?
Private Sub btn_Browse1_Click()
Dim strFilter As String
Dim strOutputFileName As String, compareFileName As String, response As Integer, fileSet As Boolean
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xlsx)", "*.xlsx")
fileSet = False
While fileSet = False
strOutputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, _
OpenFile:=False, _
DialogTitle:="Choose an image file...", _
Flags:=ahtOFN_HIDEREADONLY)
If Len(strOutputFileName) > 0 Then
compareFileName = Dir(strOutputFileName)
If compareFileName <> "" Then 'find exist file with the same name
response = MsgBox("The current file name already exists. Do you want to replace the file " & strOutputFileName & " with the current one?", vbYesNo)
If response = vbYes Then
fileSet = True 'replace old file
Kill strOutputFileName
Else
fileSet = False
End If
Else 'no file exists with the same name
fileSet = True
End If
End If
Wend
Me.txt_File_Level1.Value = strOutputFileName
【问题讨论】:
-
我建议您更改标签以包含 excel-vba 并删除 vb.net
标签: excel vba ms-access openfiledialog cancel-button