ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Opening a workbook if not opened, going to it if already opened (https://www.excelbanter.com/excel-programming/311374-opening-workbook-if-not-opened-going-if-already-opened.html)

neotokyo[_2_]

Opening a workbook if not opened, going to it if already opened
 

Your code works great...just one problem.
When the workbook file is already open, the code makes the workboo
re-open(thus asking me if I want to save changes).
How can I change the code so that if its already open, it just leave
it on(without closing and then re-opening).


Thank

--
neotoky
-----------------------------------------------------------------------
neotokyo's Profile: http://www.excelforum.com/member.php...fo&userid=1389
View this thread: http://www.excelforum.com/showthread.php?threadid=26327


Tom Ogilvy

Opening a workbook if not opened, going to it if already opened
 
No, my code doesn't do that.

Apparently you have screwed it up.

My code is tested and works fine:

Sub BBB()
Dim wkbk As Workbook
On Error Resume Next
Set wkbk = Workbooks("ABC.xls")
On Error GoTo 0
If wkbk Is Nothing Then
Set wkbk = Workbooks.Open("C:\Myfiles\ABC.xls")
End If
wkbk.Activate
End Sub


did you change the name from ABC.xls and C:\MyFiles\ABC.xls to the name/path
and name of your workbook - perhaps you have misspelled the name.

--
Regards,
Tom Ogilvy

"neotokyo" wrote in message
...

Your code works great...just one problem.
When the workbook file is already open, the code makes the workbook
re-open(thus asking me if I want to save changes).
How can I change the code so that if its already open, it just leaves
it on(without closing and then re-opening).


Thanks


--
neotokyo
------------------------------------------------------------------------
neotokyo's Profile:

http://www.excelforum.com/member.php...o&userid=13892
View this thread: http://www.excelforum.com/showthread...hreadid=263271





All times are GMT +1. The time now is 02:10 AM.

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