OPen and close file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

Hope someone can help with a inputbox
there shall contain a file name, when click
i want to close the file I work with now, and
open the other file there are written in the inputbox.

Best regards alvin
 
Alvin,

Try the following code:


Dim FName As Variant
FName = Application.GetOpenFilename("Excel Files (*.xls),*.xls")
If FName <> False Then
Workbooks.Open FName
ThisWorkbook.Close
End If



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




message
news:[email protected]...
 
If the code is in the file you want to close, the code stops when the
workbook is closed

Dim wkbkOld as Workbook, wkbk as Workbook
set wkbkOld = ActiveWorkbook
fname = Application.GetOpenfileName
if fName <> False then
set wkbk = Workbooks.Open(fName)
end if
wkbk.Close Savechanges:=True
 
Hi
I very try this but i can't

i have
Application.GetOpenFilename ("excel files (*.xls)","c:\city
breaks\priser\usa\order")

but i can't get i to work , what i want is to look after the file in the
place
c:\city breaks\priser\usa\order how do i write this
i can open in dokument and so on.

Alvin


"Chip Pearson" skrev:
 
Dim FName As Variant
Dim sStr as String
sStr = "c:\citybreaks\priser\usa\order"
chdrive sStr
chdir sStr
FName = Application.GetOpenFilename("Excel Files (*.xls),*.xls")
If FName <> False Then
Workbooks.Open FName
ThisWorkbook.Close
End If
 
Thanks for the help Tom
it's working but the first workbook dosn't close
before i close all ??

I hav try many things but it dosn't close when i open the
next workbook ??

Best regards alvin


"Tom Ogilvy" skrev:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top