ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   stop error message (https://www.excelbanter.com/excel-programming/321356-stop-error-message.html)

phil

stop error message
 
I have code written (see below) that makes sure if a workbook (TMR.xls) is
called something else or isnot located in the right folder (TMR folder), then
it will not open. It works fine if the workbook has been located in another
folder. But, if
it has the wrong name and is in the TMR folder, a Visual Basic Error message
appears saying it can't locate the workbook, AND THEN OPENS IT !!!! The visual
basic error is preventing the rest of the code, which would close the
workbook.
any suggestions how to get around this? Your help will be appreciated.

code=

If ActiveWorkbook.FullName = "C:\TMR\TMR.xls" Then
Sheets("MENU").Select
Else
Sheets("End").Select
Application.ActiveWorkbook.Save
Application.Quit



--
phil in da uk

Charles Harmon

stop error message
 
Phil,

This is similar to your previous post. Did the last suggestion work?

"phil" wrote in message
...

Charles

"phil" wrote in message
...
I have code written (see below) that makes sure if a workbook (TMR.xls) is
called something else or isnot located in the right folder (TMR folder),
then
it will not open. It works fine if the workbook has been located in
another
folder. But, if
it has the wrong name and is in the TMR folder, a Visual Basic Error
message
appears saying it can't locate the workbook, AND THEN OPENS IT !!!! The
visual
basic error is preventing the rest of the code, which would close the
workbook.
any suggestions how to get around this? Your help will be appreciated.

code=

If ActiveWorkbook.FullName = "C:\TMR\TMR.xls" Then
Sheets("MENU").Select
Else
Sheets("End").Select
Application.ActiveWorkbook.Save
Application.Quit



--
phil in da uk




phil

stop error message
 
Hi Charles
I've sorted the last problem, to get confirmation that a file exists before
opening the workbook.
This problem pertains to the actual workbook..when someone has copied
it and given it a different name. The error message comes up saying
it can't locate 'TMR.xls' but then proceeds to open the copied file. The
whole point of the exercise is to stop the workbook being copied.

"Charles Harmon" wrote:

Phil,

This is similar to your previous post. Did the last suggestion work?

"phil" wrote in message
...

Charles

"phil" wrote in message
...
I have code written (see below) that makes sure if a workbook (TMR.xls) is
called something else or isnot located in the right folder (TMR folder),
then
it will not open. It works fine if the workbook has been located in
another
folder. But, if
it has the wrong name and is in the TMR folder, a Visual Basic Error
message
appears saying it can't locate the workbook, AND THEN OPENS IT !!!! The
visual
basic error is preventing the rest of the code, which would close the
workbook.
any suggestions how to get around this? Your help will be appreciated.

code=

If ActiveWorkbook.FullName = "C:\TMR\TMR.xls" Then
Sheets("MENU").Select
Else
Sheets("End").Select
Application.ActiveWorkbook.Save
Application.Quit



--
phil in da uk





Charles Harmon

stop error message
 
Phil,
If the error is 76 then you should beable to use this code to close the
workbook. This has to be in the workbook trying to open the file.
HTH

On Error Resume Next
''' check file to see if it exist'''
If Err = "76" Then
MsgBox "File : " & "Hyperlink.twd" & " Does not exist"
Application.ActiveWorkbook.Save
Application.QUIT
end if

"phil" wrote in message
...
Hi Charles
I've sorted the last problem, to get confirmation that a file exists
before
opening the workbook.
This problem pertains to the actual workbook..when someone has copied
it and given it a different name. The error message comes up saying
it can't locate 'TMR.xls' but then proceeds to open the copied file. The
whole point of the exercise is to stop the workbook being copied.

"Charles Harmon" wrote:

Phil,

This is similar to your previous post. Did the last suggestion work?

"phil" wrote in message
...

Charles

"phil" wrote in message
...
I have code written (see below) that makes sure if a workbook (TMR.xls)
is
called something else or isnot located in the right folder (TMR
folder),
then
it will not open. It works fine if the workbook has been located in
another
folder. But, if
it has the wrong name and is in the TMR folder, a Visual Basic Error
message
appears saying it can't locate the workbook, AND THEN OPENS IT !!!! The
visual
basic error is preventing the rest of the code, which would close the
workbook.
any suggestions how to get around this? Your help will be appreciated.

code=

If ActiveWorkbook.FullName = "C:\TMR\TMR.xls" Then
Sheets("MENU").Select
Else
Sheets("End").Select
Application.ActiveWorkbook.Save
Application.Quit



--
phil in da uk







phil

stop error message
 
Hi Charles
You are mixing up 2 problems here.
I've solved the 'find hyperlink.twd' file.
This problem pertains just to the workbook. If someone has copied
the TMR.xls file and given it a different name, I want the copy to close.
What happens at the moment, is I get a message saying
RunTime error 1006 can't locate TMR.xls but then it opens the copy
...the error message is preventing the rest of the code from closing
the workbook.

"Charles Harmon" wrote:

Phil,
If the error is 76 then you should beable to use this code to close the
workbook. This has to be in the workbook trying to open the file.
HTH

On Error Resume Next
''' check file to see if it exist'''
If Err = "76" Then
MsgBox "File : " & "Hyperlink.twd" & " Does not exist"
Application.ActiveWorkbook.Save
Application.QUIT
end if

"phil" wrote in message
...
Hi Charles
I've sorted the last problem, to get confirmation that a file exists
before
opening the workbook.
This problem pertains to the actual workbook..when someone has copied
it and given it a different name. The error message comes up saying
it can't locate 'TMR.xls' but then proceeds to open the copied file. The
whole point of the exercise is to stop the workbook being copied.

"Charles Harmon" wrote:

Phil,

This is similar to your previous post. Did the last suggestion work?

"phil" wrote in message
...

Charles

"phil" wrote in message
...
I have code written (see below) that makes sure if a workbook (TMR.xls)
is
called something else or isnot located in the right folder (TMR
folder),
then
it will not open. It works fine if the workbook has been located in
another
folder. But, if
it has the wrong name and is in the TMR folder, a Visual Basic Error
message
appears saying it can't locate the workbook, AND THEN OPENS IT !!!! The
visual
basic error is preventing the rest of the code, which would close the
workbook.
any suggestions how to get around this? Your help will be appreciated.

code=

If ActiveWorkbook.FullName = "C:\TMR\TMR.xls" Then
Sheets("MENU").Select
Else
Sheets("End").Select
Application.ActiveWorkbook.Save
Application.Quit



--
phil in da uk








All times are GMT +1. The time now is 08:51 AM.

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