Force re-open file

  • Thread starter Thread starter Jamie
  • Start date Start date
J

Jamie

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
 
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
 

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