ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Force re-open file (https://www.excelbanter.com/excel-programming/301026-force-re-open-file.html)

Jamie[_9_]

Force re-open file
 
I want to open a file weather it is open already or not. (ie to
refresh the data if any changes have been made by other users). Just
using workbooks.open works fine if the user clicks yes to the "do you
want to re-open this file" dialogue but errors if the user clicks no.
It would be good to skip the dialogue box and re-open the file every
time and just open normally if the file is not open to start with.

Thanks for any help

Jamie

Frank Kabel

Force re-open file
 
Hi Jamie
you can try something like the following (only open the workbook if
it's not already opened):
sub foo()
Dim wbk As Workbook
Dim old_book as workbook
set old_book=activeworkbook
On Error Resume Next
Set wbk = Workbooks("newbook.xls")
On Error GoTo 0
If wbk Is Nothing Then
Workbooks.Open Filename:= "C:\newbook.xls"
end if
old_book.activate
end sub

--
Regards
Frank Kabel
Frankfurt, Germany


Jamie wrote:
I want to open a file weather it is open already or not. (ie to
refresh the data if any changes have been made by other users). Just
using workbooks.open works fine if the user clicks yes to the "do you
want to re-open this file" dialogue but errors if the user clicks no.
It would be good to skip the dialogue box and re-open the file every
time and just open normally if the file is not open to start with.

Thanks for any help

Jamie




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

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