ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to open and close an Excel file (https://www.excelbanter.com/excel-programming/355846-macro-open-close-excel-file.html)

Magnivy

Macro to open and close an Excel file
 
I would like to create a macro that would open an Excel file based on file
path that is indicated in a cell, and then close it. For instance, open the
file for which the file path is indicated in cell A1, and then close it.

Any advice you could provide on this would be greatly appreciated.

Magnivy

Bob Phillips[_6_]

Macro to open and close an Excel file
 
workbooks.open Range("A1").Value
...
activeworkbook.close

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Magnivy" wrote in message
...
I would like to create a macro that would open an Excel file based on file
path that is indicated in a cell, and then close it. For instance, open

the
file for which the file path is indicated in cell A1, and then close it.

Any advice you could provide on this would be greatly appreciated.

Magnivy




Henrich

Macro to open and close an Excel file
 
Hi, try this:

Sub File_Open()
file=Range("A1")
Workbooks.Open Filename:= file
ActiveWindow.Close
End Sub

€žMagnivy" napÃ*sal (napÃ*sala):

I would like to create a macro that would open an Excel file based on file
path that is indicated in a cell, and then close it. For instance, open the
file for which the file path is indicated in cell A1, and then close it.

Any advice you could provide on this would be greatly appreciated.

Magnivy


Jim Thomlinson

Macro to open and close an Excel file
 
Try this...

Sub OpenClose()
Dim wbk As Workbook

On Error Resume Next
Set wbk = Workbooks.Open(Sheets("Sheet1").Range("A1"))
On Error GoTo 0

If wbk Is Nothing Then Exit Sub

MsgBox wbk.Name & " is open."
wbk.Close

MsgBox "And now it is closed."
Set wbk = Nothing
End Sub
--
HTH...

Jim Thomlinson


"Magnivy" wrote:

I would like to create a macro that would open an Excel file based on file
path that is indicated in a cell, and then close it. For instance, open the
file for which the file path is indicated in cell A1, and then close it.

Any advice you could provide on this would be greatly appreciated.

Magnivy


kwiklearner[_5_]

Macro to open and close an Excel file
 

dim openwb as workbook
workbooks.open filename:=Range("A1")
set openwb=activeworkbook
openwb.close

Magnivy Wrote:
I would like to create a macro that would open an Excel file based on
file
path that is indicated in a cell, and then close it. For instance, open
the
file for which the file path is indicated in cell A1, and then close
it.

Any advice you could provide on this would be greatly appreciated.

Magnivy



--
kwiklearner
------------------------------------------------------------------------
kwiklearner's Profile: http://www.excelforum.com/member.php...o&userid=31909
View this thread: http://www.excelforum.com/showthread...hreadid=521717


Magnivy

Macro to open and close an Excel file
 
Many thanks to everyone for your help!! kwiklearner's code seems to work best
for me.

Magnivy
"kwiklearner" wrote:


dim openwb as workbook
workbooks.open filename:=Range("A1")
set openwb=activeworkbook
openwb.close

Magnivy Wrote:
I would like to create a macro that would open an Excel file based on
file
path that is indicated in a cell, and then close it. For instance, open
the
file for which the file path is indicated in cell A1, and then close
it.

Any advice you could provide on this would be greatly appreciated.

Magnivy



--
kwiklearner
------------------------------------------------------------------------
kwiklearner's Profile: http://www.excelforum.com/member.php...o&userid=31909
View this thread: http://www.excelforum.com/showthread...hreadid=521717




All times are GMT +1. The time now is 02:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com