I want to make sure that I'm closing an opened spreadsheet correctly. I've
been having some locking up problems. The following code adds a dummy row to
the spreadsheet to ensure that that the data gets transferred in the correct
format. It seems to be working correctly, but if anyone has any comments on
that I'd appreciate it. Right now, I'm mostly concerned about opening and
closing the spreadsheet. Here's the pertinent part of the code:
Private Sub AddDummyRow()
On Error GoTo Err_Ctrl
Dim xlsApp As Object, xlsWB As Object, xlsWS As Object
Dim mNumRows As Long, i As Integer
Dim boolXL As Boolean
'************************************************* **************
'************************************************* **************
'First, add the dummy row
'************************************************* **************
'************************************************* **************
'Check to see if Excel is running
If fIsAppRunning("Excel") Then
Set xlsApp = GetObject(, "Excel.Application")
boolXL = False
Else
Set xlsApp = CreateObject("Excel.Application")
boolXL = True
End If
'Open the workbook
Set xlsWB = xlsApp.Workbooks.Open(Me.ImportFile)
'Open the selected sheet number
Set xlsWS = xlsWB.Worksheets(CInt(Me.SheetNumber))
'Add the dummy row as the 2nd row in the spreadsheet
'First row is column headers and they will be field names in table
xlsWS.Range("A2").EntireRow.Insert
xlsWS.Cells(2, 1) = "DUMMY"
xlsWS.Cells(2, 2) = "DUMMY"
xlsWS.Cells(2, 3) = "DUMMY"
xlsWS.Cells(2, 4) = "DUMMY"
xlsWS.Cells(2, 5) = "DUMMY"
xlsWS.Cells(2, 6) = 0
xlsWS.Cells(2, 7) = 0
xlsWS.Cells(2, 8) = 0
xlsWS.Cells(2, 9) = 0
xlsWS.Cells(2, 10) = "DUMMY"
xlsWS.Cells(2, 11) = 0
xlsWS.Cells(2, 12) = 0
xlsWS.Cells(2, 13) = "DUMMY"
xlsWS.Cells(2, 14) = "DUMMY"
xlsWS.Cells(2, 15) = "DUMMY"
xlsWS.Cells(2, 16) = "DUMMY"
mNumRows = xlsWS.UsedRange.Columns.Count
'************************************************* **************
'************************************************* **************
'Second, transfer the spreadsheet to the holding table
'************************************************* **************
'************************************************* **************
Call TransferTheSpreadsheet
Exit_Sub: On Error Resume Next
'Close the instance of Excel and don't save changes
Set xlsWS = Nothing
xlsWB.Close False 'Don't save changes to the workbook.
Set xlsWB = Nothing
If boolXL Then
xlsApp.Application.Quit
End If
Set xlsApp = Nothing
DoCmd.SetWarnings True
DoCmd.Hourglass False
DoCmd.Echo True
Exit Sub
--
Message posted via http://www.accessmonster.com