PC Review


Reply
Thread Tools Rate Thread

Closing Excell from Access

 
 
John
Guest
Posts: n/a
 
      2nd Apr 2010
I'm am stuck on trying to get the instance of Excel that I am using to copy
data over to Access to close once I am done. No matter what I try, when I
look in my Task Manager there is always a hidden copy of Excel running.

Here is my code, any help would be greatly apprechiated.

Sub ImportFile()
'Asks user to select the import file and then uploads the information into
the Import table

Dim MyRS As DAO.Recordset
Dim ExcelFile As String
Dim fd As FileDialog
Dim result As Variant

Set fd = Application.FileDialog(msoFileDialogFilePicker)

'Create Open File window
With fd
.Title = "Select the Import Excel file from Card Services"
.Filters.Add "Excel File", "*.xls"
.FilterIndex = 2
.AllowMultiSelect = False
.InitialFileName = CurrentProject.Path
result = .Show
If (result <> 0) Then
ExcelFile = Trim(.SelectedItems.Item(1))
End If
End With

'Create Excel Application and open Import Excel file
Dim objXL As Excel.Application
'Set objWkb = Workbooks.Open(ExcelFile)
Set objXL = CreateObject("Excel.Application")
objXL.ScreenUpdating = True
objXL.Visible = True
objXL.Workbooks.Open (ExcelFile)

'Transfers Excel data to Access
DoCmd.SetWarnings False
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel5, "Import",
ExcelFile, True
DoCmd.SetWarnings True

'Close Excel Application
objXL.ActiveWorkbook.Close False
objXL.Quit
Set objXL = Nothing
End Sub
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      2nd Apr 2010
"John" <(E-Mail Removed)> wrote in message
news:C9EABF90-FD70-48F1-97AC-(E-Mail Removed)...
> I'm am stuck on trying to get the instance of Excel that I am using to
> copy
> data over to Access to close once I am done. No matter what I try, when I
> look in my Task Manager there is always a hidden copy of Excel running.
>
> Here is my code, any help would be greatly apprechiated.
>
> Sub ImportFile()
> 'Asks user to select the import file and then uploads the information into
> the Import table
>
> Dim MyRS As DAO.Recordset
> Dim ExcelFile As String
> Dim fd As FileDialog
> Dim result As Variant
>
> Set fd = Application.FileDialog(msoFileDialogFilePicker)
>
> 'Create Open File window
> With fd
> .Title = "Select the Import Excel file from Card Services"
> .Filters.Add "Excel File", "*.xls"
> .FilterIndex = 2
> .AllowMultiSelect = False
> .InitialFileName = CurrentProject.Path
> result = .Show
> If (result <> 0) Then
> ExcelFile = Trim(.SelectedItems.Item(1))
> End If
> End With
>
> 'Create Excel Application and open Import Excel file
> Dim objXL As Excel.Application
> 'Set objWkb = Workbooks.Open(ExcelFile)
> Set objXL = CreateObject("Excel.Application")
> objXL.ScreenUpdating = True
> objXL.Visible = True
> objXL.Workbooks.Open (ExcelFile)
>
> 'Transfers Excel data to Access
> DoCmd.SetWarnings False
> DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel5, "Import",
> ExcelFile, True
> DoCmd.SetWarnings True
>
> 'Close Excel Application
> objXL.ActiveWorkbook.Close False
> objXL.Quit
> Set objXL = Nothing
> End Sub



Is that all the relevant code? Is there any other code before you close and
destroy the Excel application object, that you haven't included in your
post? I don't get the same result -- when I execute that code, no hidden
copy of Excel remains.

I'm curious -- why are you opening Excel at all? TransferSpreadsheet
doesn't require that the Excel be running, or that the worksheet you want to
import be open.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

 
Reply With Quote
 
Ken Snell
Guest
Posts: n/a
 
      3rd Apr 2010
Try changing this line:

objXL.ActiveWorkbook.Close False


to this:

objXL.Workbooks(1).Close False


However, I do agree with Dirk that your original code shouldn't leave an
EXCEL application running.

--

Ken Snell
http://www.accessmvp.com/KDSnell/



"John" <(E-Mail Removed)> wrote in message
news:C9EABF90-FD70-48F1-97AC-(E-Mail Removed)...
> I'm am stuck on trying to get the instance of Excel that I am using to
> copy
> data over to Access to close once I am done. No matter what I try, when I
> look in my Task Manager there is always a hidden copy of Excel running.
>
> Here is my code, any help would be greatly apprechiated.
>
> Sub ImportFile()
> 'Asks user to select the import file and then uploads the information into
> the Import table
>
> Dim MyRS As DAO.Recordset
> Dim ExcelFile As String
> Dim fd As FileDialog
> Dim result As Variant
>
> Set fd = Application.FileDialog(msoFileDialogFilePicker)
>
> 'Create Open File window
> With fd
> .Title = "Select the Import Excel file from Card Services"
> .Filters.Add "Excel File", "*.xls"
> .FilterIndex = 2
> .AllowMultiSelect = False
> .InitialFileName = CurrentProject.Path
> result = .Show
> If (result <> 0) Then
> ExcelFile = Trim(.SelectedItems.Item(1))
> End If
> End With
>
> 'Create Excel Application and open Import Excel file
> Dim objXL As Excel.Application
> 'Set objWkb = Workbooks.Open(ExcelFile)
> Set objXL = CreateObject("Excel.Application")
> objXL.ScreenUpdating = True
> objXL.Visible = True
> objXL.Workbooks.Open (ExcelFile)
>
> 'Transfers Excel data to Access
> DoCmd.SetWarnings False
> DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel5, "Import",
> ExcelFile, True
> DoCmd.SetWarnings True
>
> 'Close Excel Application
> objXL.ActiveWorkbook.Close False
> objXL.Quit
> Set objXL = Nothing
> End Sub



 
Reply With Quote
 
John
Guest
Posts: n/a
 
      5th Apr 2010
Thanks!

I'm new to Access, and I wasn't aware you didn't have to open Excel in order
to copy over a spreadsheet.

"Dirk Goldgar" wrote:

> "John" <(E-Mail Removed)> wrote in message
> news:C9EABF90-FD70-48F1-97AC-(E-Mail Removed)...
> > I'm am stuck on trying to get the instance of Excel that I am using to
> > copy
> > data over to Access to close once I am done. No matter what I try, when I
> > look in my Task Manager there is always a hidden copy of Excel running.
> >
> > Here is my code, any help would be greatly apprechiated.
> >
> > Sub ImportFile()
> > 'Asks user to select the import file and then uploads the information into
> > the Import table
> >
> > Dim MyRS As DAO.Recordset
> > Dim ExcelFile As String
> > Dim fd As FileDialog
> > Dim result As Variant
> >
> > Set fd = Application.FileDialog(msoFileDialogFilePicker)
> >
> > 'Create Open File window
> > With fd
> > .Title = "Select the Import Excel file from Card Services"
> > .Filters.Add "Excel File", "*.xls"
> > .FilterIndex = 2
> > .AllowMultiSelect = False
> > .InitialFileName = CurrentProject.Path
> > result = .Show
> > If (result <> 0) Then
> > ExcelFile = Trim(.SelectedItems.Item(1))
> > End If
> > End With
> >
> > 'Create Excel Application and open Import Excel file
> > Dim objXL As Excel.Application
> > 'Set objWkb = Workbooks.Open(ExcelFile)
> > Set objXL = CreateObject("Excel.Application")
> > objXL.ScreenUpdating = True
> > objXL.Visible = True
> > objXL.Workbooks.Open (ExcelFile)
> >
> > 'Transfers Excel data to Access
> > DoCmd.SetWarnings False
> > DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel5, "Import",
> > ExcelFile, True
> > DoCmd.SetWarnings True
> >
> > 'Close Excel Application
> > objXL.ActiveWorkbook.Close False
> > objXL.Quit
> > Set objXL = Nothing
> > End Sub

>
>
> Is that all the relevant code? Is there any other code before you close and
> destroy the Excel application object, that you haven't included in your
> post? I don't get the same result -- when I execute that code, no hidden
> copy of Excel remains.
>
> I'm curious -- why are you opening Excel at all? TransferSpreadsheet
> doesn't require that the Excel be running, or that the worksheet you want to
> import be open.
>
> --
> Dirk Goldgar, MS Access MVP
> Access tips: www.datagnostics.com/tips.html
>
> (please reply to the newsgroup)
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing documents in Excell & Word laslo Microsoft Excel Misc 1 5th Aug 2004 12:29 AM
Re: excell keeps opening & closing immediately NobodyMan Windows XP General 0 12th May 2004 01:28 AM
Re: excell keeps opening & closing immediately Steve Nielsen Windows XP General 0 11th May 2004 10:09 PM
Re: excell keeps opening & closing immediately hermes Windows XP General 0 11th May 2004 09:17 PM
Re: closing out excell Ken Wright Microsoft Excel Misc 0 22nd Jul 2003 10:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:43 AM.