LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default excel instance stays open

Hello,
I asked this in the access forum and I couldnt get an answer that worked.
Just wondering if you guys know because its about excel automation

I am having an issue with the following code.
I have searched around for the answer but I cannot get anything I find to
work.
I know I must be missing something simple. When the code is run I still have
an instance of Excel open that holds up the future running of the code (plus
hogs system resource)
I thought that having
xlApp.Quit
set xlApp = Nothing
is supposed to get rid of that.
Please help.

David

PS I think that it is the following line that is causing the extra instance;
With xlApp.ActiveSheet.QueryTables.Add(Connection:= _
strConnection _
, Destination:=Range("A1"))



Private Sub Import_Click()
Dim CheckDate As Date
Dim CheckFlightNoSheet, CheckFlightNoForm As String

Dim xlApp As Excel.Application
Dim strConnection As String

'On Error GoTo err_Import_Click

DoCmd.SetWarnings (WarningsOff)
DoCmd.OpenQuery "DeleteImport"

'Import file from HTM sheet
Set xlApp = CreateObject("Excel.Application")

xlApp.Workbooks.Add

strConnection =
"FINDER;file:///C:/Documents%20and%20Settings/David/My%20Documents/Work/Xfer/Flight_" & Me.FlightNoInput & ".htm"

With xlApp.ActiveSheet.QueryTables.Add(Connection:= _
strConnection _
, Destination:=Range("A1"))
.Name = "Flight_List"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With

'Format Sheet
With xlApp
.Columns("B:B").Select
.Selection.TextToColumns Destination:=Range("B1"),
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False,
FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
.Columns("F:F").Select
.Selection.TextToColumns Destination:=Range("F1"),
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(6, 1)),
TrailingMinusNumbers:=True
.ActiveWindow.SmallScroll Down:=-72
.Columns("G:G").Select
.Selection.Cut
.Columns("D:D").Select
.Selection.Insert Shift:=xlToRight
.Range("A1:A3").Select
.Selection.Cut Destination:=Range("B1:B3")
.Columns("A:A").Select
.Selection.Delete Shift:=xlToLeft
.Columns("E:R").Select
.Selection.Delete Shift:=xlToLeft
.Range("A7").Select
.ActiveCell.FormulaR1C1 = "LastName"
.Range("B7").Select
.ActiveCell.FormulaR1C1 = "FirstName"
.Range("C7").Select
.ActiveCell.FormulaR1C1 = "Destination"
.Range("D7").Select
.ActiveCell.FormulaR1C1 = "LocatorCode"
.Range("A1").Select
End With

xlApp.ActiveWorkbook.SaveAs Filename:= _
"C:/Documents and Settings/David/My
Documents/Work/Xfer/CurrentImport.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

'xlApp.Visible = True

'Check that flight date on manifest and screen match
CheckDate = xlApp.ActiveSheet.Range("A2")
CheckFlightNoSheet = xlApp.ActiveSheet.Range("A1")
CheckFlightNoForm = "FLIGHT # " & Me.FlightNoInput

If CheckDate < Me.FlightDate Then
MsgBox "The date does not match up. Please check, process
terminated.", vbCritical, "Information Error!"
GoTo exit_Import_Click
End If
If CheckFlightNoSheet < CheckFlightNoForm Then
MsgBox "The flight number does not match up. Please check, process
terminated.", vbCritical, "Information Error!"
GoTo exit_Import_Click
End If


exit_Import_Click:
On Error GoTo 0
xlApp.Quit
Set xlApp = Nothing
DoCmd.SetWarnings (WarningsOn)

Exit Sub

err_Import_Click:
Select Case Err.Number

Case Else
MsgBox "Please Report! " & Err.Number & " (" & Err.Description & ")
in procedure Import_Click of VBA Document Form_Import", vbExclamation
Resume exit_Import_Click
End Select

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to open a new instance of EXCEL and .xls file Launchnet Excel Worksheet Functions 10 June 19th 07 03:45 PM
open excel in a separate instance Eric Excel Discussion (Misc queries) 0 March 9th 07 08:01 PM
Open files within one instance of Excel kopa999 Setting up and Configuration of Excel 1 March 22nd 06 11:40 PM
How do i open a new instance Excel? Michael D. Reed Excel Programming 18 July 3rd 05 07:50 PM
EXCEL.exe stays open after Quit method in an HTA myriams9 Excel Programming 5 December 4th 03 07:06 AM


All times are GMT +1. The time now is 08:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"