Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Check if workbook open (Not working)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick Kirk - 24 Jan 2008 17:05 GMT
Hi,

My program starts with a simple form to create a new workbook or open an
existing one. Once you do either, the form disappears and either opens or
starts an new workbook. Once you close either the newly created workbook or
the existing one, the form re-appears asking you the same question of
creating a new workbook and/or opening an existing one. If the user selects
to open an existing workbook and that workbook is the name of the previous
workbook he/she has opened prior, in actuality the workbook may very well
already be open but not active or visible. My code below checks if the
workbook is already opened and if so, closes it and re-opens it.

Problem:
If the workbook is open the code will close it and the program will go dead
stopping after (Workbooks(StrWkBk).Close savechanges:=False). Is there a way
to force the program/script to continue?

On Error resume next
ThisWorkbook.Activate
Workbooks(StrWkBk).Close savechanges:=False

Set wbResults1 = Workbooks.Open(StrName)
Signature

PK

mikelee101 - 24 Jan 2008 17:23 GMT
Hello Patrick,
Not sure, but two things you can look at.  First is that your variables are
different in the close and open statements.  Didn't know if that was by
design or not, but could contribute.  The other suggestion might be to add

On Error Goto 0

between the close statement and open statement then run it again and see if
you get an error message.  I don't know that the code might be going dead so
much as maybe there's an error in that line, but it's simply passing it over
due to the resume next statement.

Don't know if that will help or not.

Good luck.

Signature

Mike Lee
McKinney,TX USA

> Hi,
>
[quoted text clipped - 18 lines]
>
> Set wbResults1 = Workbooks.Open(StrName)
Patrick Kirk - 24 Jan 2008 17:37 GMT
Mike,

Thanks for the response. Code continues to stop or go dead. Im not able to
execute the following lines.
Signature

PK

> Hello Patrick,
> Not sure, but two things you can look at.  First is that your variables are
[quoted text clipped - 34 lines]
> >
> > Set wbResults1 = Workbooks.Open(StrName)
JLGWhiz - 24 Jan 2008 19:23 GMT
If you are closing the workbook that contains the code, then it will go dead
and there is no way to continue.  I am not sure why you have the
ThisWorkbook.Activate  line in there because if it is not the workbook being
closed and is the remaining workbook, it automatically becomes the active
workbook.

> Mike,
>
[quoted text clipped - 39 lines]
> > >
> > > Set wbResults1 = Workbooks.Open(StrName)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.