S
SaeOngJeeMa
Hello, I'm having a problem with one of my Excel files. Whenever I close the
file I get a warning message:
"This workbook is referenced by another workbook and cannot be closed"
I never referenced this through any other workbooks to my knowledge. The
only thing I can think of is there is one sub in the workbook that does a SQL
query on the data within one of the worksheets. I pasted the code from that
sub below. Thanks in advance for any help you can provide.
--
Best Regards,
Dean
Public Sub rewriteFSFDataToWsht(strMeasConfig As String)
On Error GoTo Err_rewriteFSFDataToWsht
'*********************************************************************
'Name:
' rewriteFSFDataToWsht
'Type:
' Public subroutine, Excel VBA
'Author:
' Dean Faith
'History:
' Last updated 2006/11/30
'Purpose:
' clears current data from the FSF worksheet, requeries the
Master worksheet with the latest
' customer inputs on the Meas controls and writes the data
to the worksheet
'Args:
' strMeasConfig
'Returns:
' nothing
'Notes:
' none
'*********************************************************************
Dim rngTemp As Range
Dim rstData As ADODB.Recordset
Dim strConnection As String
Dim strSQL As String
'allow changes to the FSF worksheet
gbytFSFWshtChangeIgnoreFlag = gcbytTrue
'clear the old contents of the worksheet
With Worksheets("FSF")
Set rngTemp = .Range(.Cells(3, 1), .Cells.SpecialCells(xlLastCell))
End With
rngTemp.ClearContents
' Create the connection string.
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\FILEBOX\ProductivityTools\DFTTI.xls;" & _
"Extended Properties=Excel 8.0;"
strSQL = buildFSFSQLString(strMeasConfig)
Set rstData = New ADODB.Recordset
rstData.Open strSQL, strConnection, adOpenForwardOnly, adLockReadOnly,
adCmdText
'verify data were received, if so write to worksheet, if not warn the user
If Not rstData.EOF Then
Worksheets("FSF").Range("A3").CopyFromRecordset rstData
Else
MsgBox "No records returned.", vbCritical
End If
'clear row of data I used to get the desired QAR order- pretty cheesy but
it works
With Worksheets("FSF")
Set rngTemp = .Range(.Cells(3, 31), .Cells.SpecialCells(xlLastCell))
End With
rngTemp.ClearContents
'reset protection from changes to the FSF worksheet
gbytFSFWshtChangeIgnoreFlag = gcbytFalse
'set the proper number format for the data cells
Call formatFSFWshtCells
'Clean up object and control variables
rstData.Close
Set rstData = Nothing
Set rngTemp = Nothing
'reset the range variables for the FSF worksheet
Call setWorksheetDataRangesFSF
Exit_rewriteFSFDataToWsht:
Exit Sub
Err_rewriteFSFDataToWsht:
MsgBox "sub rewriteFSFDataToWsht " & Err.Description
Resume Exit_rewriteFSFDataToWsht
End Sub
file I get a warning message:
"This workbook is referenced by another workbook and cannot be closed"
I never referenced this through any other workbooks to my knowledge. The
only thing I can think of is there is one sub in the workbook that does a SQL
query on the data within one of the worksheets. I pasted the code from that
sub below. Thanks in advance for any help you can provide.
--
Best Regards,
Dean
Public Sub rewriteFSFDataToWsht(strMeasConfig As String)
On Error GoTo Err_rewriteFSFDataToWsht
'*********************************************************************
'Name:
' rewriteFSFDataToWsht
'Type:
' Public subroutine, Excel VBA
'Author:
' Dean Faith
'History:
' Last updated 2006/11/30
'Purpose:
' clears current data from the FSF worksheet, requeries the
Master worksheet with the latest
' customer inputs on the Meas controls and writes the data
to the worksheet
'Args:
' strMeasConfig
'Returns:
' nothing
'Notes:
' none
'*********************************************************************
Dim rngTemp As Range
Dim rstData As ADODB.Recordset
Dim strConnection As String
Dim strSQL As String
'allow changes to the FSF worksheet
gbytFSFWshtChangeIgnoreFlag = gcbytTrue
'clear the old contents of the worksheet
With Worksheets("FSF")
Set rngTemp = .Range(.Cells(3, 1), .Cells.SpecialCells(xlLastCell))
End With
rngTemp.ClearContents
' Create the connection string.
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\FILEBOX\ProductivityTools\DFTTI.xls;" & _
"Extended Properties=Excel 8.0;"
strSQL = buildFSFSQLString(strMeasConfig)
Set rstData = New ADODB.Recordset
rstData.Open strSQL, strConnection, adOpenForwardOnly, adLockReadOnly,
adCmdText
'verify data were received, if so write to worksheet, if not warn the user
If Not rstData.EOF Then
Worksheets("FSF").Range("A3").CopyFromRecordset rstData
Else
MsgBox "No records returned.", vbCritical
End If
'clear row of data I used to get the desired QAR order- pretty cheesy but
it works
With Worksheets("FSF")
Set rngTemp = .Range(.Cells(3, 31), .Cells.SpecialCells(xlLastCell))
End With
rngTemp.ClearContents
'reset protection from changes to the FSF worksheet
gbytFSFWshtChangeIgnoreFlag = gcbytFalse
'set the proper number format for the data cells
Call formatFSFWshtCells
'Clean up object and control variables
rstData.Close
Set rstData = Nothing
Set rngTemp = Nothing
'reset the range variables for the FSF worksheet
Call setWorksheetDataRangesFSF
Exit_rewriteFSFDataToWsht:
Exit Sub
Err_rewriteFSFDataToWsht:
MsgBox "sub rewriteFSFDataToWsht " & Err.Description
Resume Exit_rewriteFSFDataToWsht
End Sub