新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Sub Command1_Click()
Dim intFileNum%: intFileNum = FreeFile
On Error Resume Next
Open App.Path & "\abc.txt" For Input As #intFileNum
If Err.Number <> 0 Then
MsgBox "无法打开文件!", vbCritical, "失败"
Exit Sub
End If
On Error GoTo 0
End Sub