I am having trouble with the following function. I am trying alert users to close the spreadsheet, if it is open, before executing a command. The function is just bypassing the whole part about whether the spreadsheet is open or not. Any help would be greatly appreciated.
Private Function WorkbookIsOpen(wbname) As Boolean
' Returns TRUE if the workbook is open
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbname)
If Err = 0 Then WorkbookIsOpen = True _
Else WorkbookIsOpen = False
End Function
Private Sub cmdNewBusCon_Click()
Dim stDocName As String
If WorkbookIsOpen("test.xls"
= True Then
MsgBox ("Please save your spreadsheets and close them"
Else:
DoCmd.OutputTo acOutputTable, "OneClickNewNotifsForBoth", "Microsoft Excel (*.xls)", "C:\test.xls", True
Exit Sub
End If
Exit_cmdNewBusCon_Click:
Exit Sub
End Sub
Private Function WorkbookIsOpen(wbname) As Boolean
' Returns TRUE if the workbook is open
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbname)
If Err = 0 Then WorkbookIsOpen = True _
Else WorkbookIsOpen = False
End Function
Private Sub cmdNewBusCon_Click()
Dim stDocName As String
If WorkbookIsOpen("test.xls"
MsgBox ("Please save your spreadsheets and close them"
Else:
DoCmd.OutputTo acOutputTable, "OneClickNewNotifsForBoth", "Microsoft Excel (*.xls)", "C:\test.xls", True
Exit Sub
End If
Exit_cmdNewBusCon_Click:
Exit Sub
End Sub