PC Review


Reply
Thread Tools Rate Thread

Closing Files Opened Using the FileToOpen

 
 
=?Utf-8?B?RCBaYW5kdmVsZA==?=
Guest
Posts: n/a
 
      21st Feb 2007
Hi Again

I have opened a file successfully (user defined and stored as FileToOpen)
and copied it's content into the active worksheet.
However, since it opens a new instance of Excel, I can't work out how to
close the FileToOpen file, and where the command belongs in the code below.

-----------------------------------------------------------------------------

Worksheets("Imported Data").Visible = True

With Application.FileDialog(msoFileDialogOpen)
FileToOpen = Application _
.GetOpenFilename("Comma Separated Values (*.csv),*.csv,Microsoft
Excel (*.xls),*.xls,All Files (*.*),*.*")
Workbooks.Open FileToOpen
Range("A1").Activate
Application.Run ("'Report Generator v1.xls'!Select_Data")
Selection.Copy
Workbooks("'Report Generator v1.xls").Activate
Sheets("Imported Data").Activate
Range("A1").Select
Selection.Insert Shift:=xlDown

***I assume here I need to switch to the other workbook
(FileToOpen), close it, then switch back to ("Report Generator v1.xls")***

End With
Worksheets("Imported Data").Visible = False
Sheets("Main").Activate
 
Reply With Quote
 
 
 
 
Tim Williams
Guest
Posts: n/a
 
      21st Feb 2007

dim oWB
set oWB = Workbooks.Open(FileToOpen)

' do stuff with oWB

oWB.Close


Tim




"D Zandveld" <(E-Mail Removed)> wrote in message
news:2350E516-AD80-4A90-8CBA-(E-Mail Removed)...
> Hi Again
>
> I have opened a file successfully (user defined and stored as FileToOpen)
> and copied it's content into the active worksheet.
> However, since it opens a new instance of Excel, I can't work out how to
> close the FileToOpen file, and where the command belongs in the code
> below.
>
> -----------------------------------------------------------------------------
>
> Worksheets("Imported Data").Visible = True
>
> With Application.FileDialog(msoFileDialogOpen)
> FileToOpen = Application _
> .GetOpenFilename("Comma Separated Values
> (*.csv),*.csv,Microsoft
> Excel (*.xls),*.xls,All Files (*.*),*.*")
> Workbooks.Open FileToOpen
> Range("A1").Activate
> Application.Run ("'Report Generator v1.xls'!Select_Data")
> Selection.Copy
> Workbooks("'Report Generator v1.xls").Activate
> Sheets("Imported Data").Activate
> Range("A1").Select
> Selection.Insert Shift:=xlDown
>
> ***I assume here I need to switch to the other workbook
> (FileToOpen), close it, then switch back to ("Report Generator v1.xls")***
>
> End With
> Worksheets("Imported Data").Visible = False
> Sheets("Main").Activate



 
Reply With Quote
 
=?Utf-8?B?RCBaYW5kdmVsZA==?=
Guest
Posts: n/a
 
      21st Feb 2007
Great Stuff, Thanks Tim.

"Tim Williams" wrote:

>
> dim oWB
> set oWB = Workbooks.Open(FileToOpen)
>
> ' do stuff with oWB
>
> oWB.Close
>
>
> Tim
>
>
>
>
> "D Zandveld" <(E-Mail Removed)> wrote in message
> news:2350E516-AD80-4A90-8CBA-(E-Mail Removed)...
> > Hi Again
> >
> > I have opened a file successfully (user defined and stored as FileToOpen)
> > and copied it's content into the active worksheet.
> > However, since it opens a new instance of Excel, I can't work out how to
> > close the FileToOpen file, and where the command belongs in the code
> > below.
> >
> > -----------------------------------------------------------------------------
> >
> > Worksheets("Imported Data").Visible = True
> >
> > With Application.FileDialog(msoFileDialogOpen)
> > FileToOpen = Application _
> > .GetOpenFilename("Comma Separated Values
> > (*.csv),*.csv,Microsoft
> > Excel (*.xls),*.xls,All Files (*.*),*.*")
> > Workbooks.Open FileToOpen
> > Range("A1").Activate
> > Application.Run ("'Report Generator v1.xls'!Select_Data")
> > Selection.Copy
> > Workbooks("'Report Generator v1.xls").Activate
> > Sheets("Imported Data").Activate
> > Range("A1").Select
> > Selection.Insert Shift:=xlDown
> >
> > ***I assume here I need to switch to the other workbook
> > (FileToOpen), close it, then switch back to ("Report Generator v1.xls")***
> >
> > End With
> > Worksheets("Imported Data").Visible = False
> > Sheets("Main").Activate

>
>
>

 
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 a window opened in a frame Garg Microsoft VB .NET 1 28th Feb 2007 03:29 PM
Closing a workbook after it has opened another belkingold Microsoft Excel Programming 5 30th Oct 2006 06:51 PM
Outlook keeps closing after being opened . How do i fix this? =?Utf-8?B?Sm9obiBD?= Microsoft Outlook Discussion 0 2nd Feb 2006 04:23 AM
Closing an application before it's opened. ssg31415926 Microsoft Dot NET Framework Forms 2 12th Aug 2005 03:39 PM
Closing Opened Files =?Utf-8?B?R2FicmllbCBHaXJhbGRv?= Microsoft Windows 2000 2 29th Jun 2005 07:30 PM


Features
 

Advertising
 

Newsgroups
 


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