Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing a file(any file) retrieved by GetOpenFilename method

Status
Not open for further replies.

romij29

Technical User
Nov 23, 2004
49
GB
Hello ,

Wondering if anyone out there could come to the assistance of a vba newbie.

I have a getopenfilename program that opens a dialog box and enbles me to choose a file that opens up. From there.I copy a sheet to another worksheet.
However, how do I close the file retrieved through the GetOpenFilename method after copying data from it. More importantly,what code would I have to use to basically close "any" file chosen thru the GetOpenFilename method.

Also how do I choose two files from the open dialog box at the same time?Tried changing mutiselect to true in the GetOpenFilename expression but doesn't make a difference.The two files i want to choose are in different folders.Is that a problem?

Here is my code so far:

Sub mnuFileOpen_Click()
Dim FullFileName As String

FullFileName = Application.GetOpenFilename("Excel Files (*.xls),*.xls", True)

Application.StatusBar = "Opening " & FullFileName

Workbooks.Open FullFileName

Sheets(1).Range("A:H").Copy

Workbooks("Trading Accounts.xls").Activate
Sheets("FMA Data").Select
Range("A1").Select
Selection.PasteSpecial xlValues

'Workbooks("Trading Accounts.xls").Sheets("FMA Data").Range("A1").PasteSpecial xlValues

Application.CutCopyMode = False


Application.StatusBar = "Closing " & FullFileName

Application.Windows(FullFileName).Close

Application.StatusBar = False

End Sub


Thanks for your time.

romij29
 
Hi romij29,

How you get the filename is not important. How you open the file is what matters. In this case you opened your file with Excel, so you close it with Excel:
[blue][tt] Workbooks(FullFileName).Close[/tt][/blue]

As far as selecting two files from two different folders, I don't think you can do it in one dialog. What about a Userform with two separate textboxes, each with its own 'browse' button?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Hello,

Tried that but did not work.
Thanks for the tip anyway.Is there any other way of multiselecting apart from creating a new user form..??
Thanks
 
Replace this:
Workbooks.Open FullFileName
By this:
Set myWB = Workbooks.Open(FullFileName)
And this:
Application.Windows(FullFileName).Close
By this:
myWB.Close
Set myWB = Nothing

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV,

Thanks a lot.It worked a charm. Is
it possible to set the multiselect to True and select two files in different folders within the same dialog box.
If so, how can this be done?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top