PC Review


Reply
Thread Tools Rate Thread

Check if workbook open (Not working)

 
 
Patrick Kirk
Guest
Posts: n/a
 
      24th Jan 2008
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)
--
PK
 
Reply With Quote
 
 
 
 
mikelee101
Guest
Posts: n/a
 
      24th Jan 2008
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.

--
Mike Lee
McKinney,TX USA


"Patrick Kirk" wrote:

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

 
Reply With Quote
 
Patrick Kirk
Guest
Posts: n/a
 
      24th Jan 2008
Mike,

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


"mikelee101" wrote:

> 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.
>
> --
> Mike Lee
> McKinney,TX USA
>
>
> "Patrick Kirk" wrote:
>
> > 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)
> > --
> > PK

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      24th Jan 2008
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.

"Patrick Kirk" wrote:

> Mike,
>
> Thanks for the response. Code continues to stop or go dead. Im not able to
> execute the following lines.
> --
> PK
>
>
> "mikelee101" wrote:
>
> > 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.
> >
> > --
> > Mike Lee
> > McKinney,TX USA
> >
> >
> > "Patrick Kirk" wrote:
> >
> > > 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)
> > > --
> > > PK

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to check is someone else has a workbook open Jim K. Microsoft Excel Misc 2 29th Aug 2008 04:32 PM
If Then to check if a workbook is open =?Utf-8?B?U2hhd24=?= Microsoft Excel Misc 5 25th Nov 2006 04:29 PM
Check if workbook is already open... Cumberland Microsoft Excel Programming 1 22nd Aug 2006 09:16 AM
Check if workbook open dkipping Microsoft Excel Misc 4 24th May 2006 02:00 PM
Check workbook open or not =?Utf-8?B?RXZh?= Microsoft Excel Misc 1 7th Nov 2003 03:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:33 AM.