![]() |
How to Write Error Trap
I have the following code to toggle between print preview and normal
view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
Sub TogglePrintView()
If Not Activesheet is Nothing Then ActiveWindow.View = 3- ActiveWindow.View End Sub If this post helps click Yes --------------- Jacob Skaria "GavinS" wrote: I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
On Jun 4, 12:49*pm, Jacob Skaria
wrote: Sub TogglePrintView() If Not Activesheet is Nothing Then ActiveWindow.View = 3- ActiveWindow.View End Sub If this post helps click Yes --------------- Jacob Skaria "GavinS" wrote: I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() * * If ActiveWindow.View = xlPageBreakPreview Then * * *ActiveWindow.View = xlNormalView * * *ElseIf ActiveWindow.View = xlNormalView Then * * * * ActiveWindow.View = xlPageBreakPreview * * End If End Sub- Hide quoted text - - Show quoted text - Nope, pasted that before the first line of code and it returns an error |
How to Write Error Trap
On Jun 4, 12:49*pm, Jacob Skaria
wrote: Sub TogglePrintView() If Not Activesheet is Nothing Then ActiveWindow.View = 3- ActiveWindow.View End Sub If this post helps click Yes --------------- Jacob Skaria "GavinS" wrote: I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() * * If ActiveWindow.View = xlPageBreakPreview Then * * *ActiveWindow.View = xlNormalView * * *ElseIf ActiveWindow.View = xlNormalView Then * * * * ActiveWindow.View = xlPageBreakPreview * * End If End Sub- Hide quoted text - - Show quoted text - Nope, pasted that before the first line of code and it returns an error |
How to Write Error Trap
How can you have a workbook with no sheet open?
Does the code below ever stop by error? Keiji GavinS wrote: I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
How can you have a workbook with no sheet open?
Does the code below ever stop by error? Keiji GavinS wrote: I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
if there's no workbook open (1) where would you put the code and (2) print /
print preview isn't available "GavinS" wrote in message ... I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
Then, How can you run the macro?
Keiji Patrick Molloy wrote: if there's no workbook open (1) where would you put the code and (2) print / print preview isn't available "GavinS" wrote in message ... I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
Then, How can you run the macro?
Keiji Patrick Molloy wrote: if there's no workbook open (1) where would you put the code and (2) print / print preview isn't available "GavinS" wrote in message ... I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
It can even be a procedure within an Add-In..
GavinS '"Nope, pasted that before the first line of code and it returns an error" As mentioned above you should not be pasting the below code to the other procedure. The procedure itself is re-written to suit your requirement. So try with the new procedure. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Then, How can you run the macro? Keiji Patrick Molloy wrote: if there's no workbook open (1) where would you put the code and (2) print / print preview isn't available "GavinS" wrote in message ... I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
Even if that macro is within an Add-in, Is there a situation that there
is no workbook and no active window? if there is such a situation, that macro surely would fails. but i can't imagine such a situation. Keiji Jacob Skaria wrote: It can even be a procedure within an Add-In.. GavinS '"Nope, pasted that before the first line of code and it returns an error" As mentioned above you should not be pasting the below code to the other procedure. The procedure itself is re-written to suit your requirement. So try with the new procedure. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Then, How can you run the macro? Keiji Patrick Molloy wrote: if there's no workbook open (1) where would you put the code and (2) print / print preview isn't available "GavinS" wrote in message ... I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
Even if that macro is within an Add-in, Is there a situation that there
is no workbook and no active window? if there is such a situation, that macro surely would fails. but i can't imagine such a situation. Keiji Jacob Skaria wrote: It can even be a procedure within an Add-In.. GavinS '"Nope, pasted that before the first line of code and it returns an error" As mentioned above you should not be pasting the below code to the other procedure. The procedure itself is re-written to suit your requirement. So try with the new procedure. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Then, How can you run the macro? Keiji Patrick Molloy wrote: if there's no workbook open (1) where would you put the code and (2) print / print preview isn't available "GavinS" wrote in message ... I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
Try saving a workbook as .xla and open it. From VBE check out your project
explorer. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Even if that macro is within an Add-in, Is there a situation that there is no workbook and no active window? if there is such a situation, that macro surely would fails. but i can't imagine such a situation. Keiji Jacob Skaria wrote: It can even be a procedure within an Add-In.. GavinS '"Nope, pasted that before the first line of code and it returns an error" As mentioned above you should not be pasting the below code to the other procedure. The procedure itself is re-written to suit your requirement. So try with the new procedure. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Then, How can you run the macro? Keiji Patrick Molloy wrote: if there's no workbook open (1) where would you put the code and (2) print / print preview isn't available "GavinS" wrote in message ... I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
I understand what you are saying at last, but is this usual way of using
add-in? How can i use this macro in this case? I think i need to write some macro to add a menu to use this macro into Workbook_Open procedure. Keiji Jacob Skaria wrote: Try saving a workbook as .xla and open it. From VBE check out your project explorer. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Even if that macro is within an Add-in, Is there a situation that there is no workbook and no active window? if there is such a situation, that macro surely would fails. but i can't imagine such a situation. Keiji Jacob Skaria wrote: It can even be a procedure within an Add-In.. GavinS '"Nope, pasted that before the first line of code and it returns an error" As mentioned above you should not be pasting the below code to the other procedure. The procedure itself is re-written to suit your requirement. So try with the new procedure. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Then, How can you run the macro? Keiji Patrick Molloy wrote: if there's no workbook open (1) where would you put the code and (2) print / print preview isn't available "GavinS" wrote in message ... I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
I understand what you are saying at last, but is this usual way of using
add-in? How can i use this macro in this case? I think i need to write some macro to add a menu to use this macro into Workbook_Open procedure. Keiji Jacob Skaria wrote: Try saving a workbook as .xla and open it. From VBE check out your project explorer. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Even if that macro is within an Add-in, Is there a situation that there is no workbook and no active window? if there is such a situation, that macro surely would fails. but i can't imagine such a situation. Keiji Jacob Skaria wrote: It can even be a procedure within an Add-In.. GavinS '"Nope, pasted that before the first line of code and it returns an error" As mentioned above you should not be pasting the below code to the other procedure. The procedure itself is re-written to suit your requirement. So try with the new procedure. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Then, How can you run the macro? Keiji Patrick Molloy wrote: if there's no workbook open (1) where would you put the code and (2) print / print preview isn't available "GavinS" wrote in message ... I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
I'd add something like this to the top of the procedu
If ActiveWindow Is Nothing Then Exit Sub End If GavinS wrote: I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub -- Dave Peterson |
How to Write Error Trap
I'd add something like this to the top of the procedu
If ActiveWindow Is Nothing Then Exit Sub End If GavinS wrote: I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub -- Dave Peterson |
How to Write Error Trap
What do you want to do when error occur?
if you want to just ignore, one way is like this. Sub TogglePrintView() on error goto ex If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If exit sub ex: msgbox "there is no sheet open" <<==if not need, delete this End Sub By the way, are you using this macro in Add-in? Keiji GavinS wrote: I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
What do you want to do when error occur?
if you want to just ignore, one way is like this. Sub TogglePrintView() on error goto ex If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If exit sub ex: msgbox "there is no sheet open" <<==if not need, delete this End Sub By the way, are you using this macro in Add-in? Keiji GavinS wrote: I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
Thanks for all the interesting discussion. The macro is called from a button or shortcut so can be called when ActiveWindow is nothing. I used Dave Peterson's code and that seems to work fine If ActiveWindow Is Nothing Then Exit Sub End If Thanks again |
How to Write Error Trap
Thanks for all the interesting discussion. The macro is called from a button or shortcut so can be called when ActiveWindow is nothing. I used Dave Peterson's code and that seems to work fine If ActiveWindow Is Nothing Then Exit Sub End If Thanks again |
How to Write Error Trap
I realize that i had a big misunderstanding. there is a situation with
no sheet open in a ordinary use. just to hide the Workbook that your macro is written is enough for your macro without error trap to fail. Sorry for useless discussion. Keiji GavinS wrote: Thanks for all the interesting discussion. The macro is called from a button or shortcut so can be called when ActiveWindow is nothing. I used Dave Peterson's code and that seems to work fine If ActiveWindow Is Nothing Then Exit Sub End If Thanks again |
How to Write Error Trap
Option Explicit
Sub TogglePrintView() Dim wndw As Window Set wndw = ActiveWindow If Not wndw Is Nothing Then If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End If End Sub "keiji kounoike" <"kounoike AT mbh.nifty.com" wrote in message ... I understand what you are saying at last, but is this usual way of using add-in? How can i use this macro in this case? I think i need to write some macro to add a menu to use this macro into Workbook_Open procedure. Keiji Jacob Skaria wrote: Try saving a workbook as .xla and open it. From VBE check out your project explorer. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Even if that macro is within an Add-in, Is there a situation that there is no workbook and no active window? if there is such a situation, that macro surely would fails. but i can't imagine such a situation. Keiji Jacob Skaria wrote: It can even be a procedure within an Add-In.. GavinS '"Nope, pasted that before the first line of code and it returns an error" As mentioned above you should not be pasting the below code to the other procedure. The procedure itself is re-written to suit your requirement. So try with the new procedure. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Then, How can you run the macro? Keiji Patrick Molloy wrote: if there's no workbook open (1) where would you put the code and (2) print / print preview isn't available "GavinS" wrote in message ... I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
Hi Patrick
I can't get it why you post the code below to my post. Keiji Patrick Molloy wrote: Option Explicit Sub TogglePrintView() Dim wndw As Window Set wndw = ActiveWindow If Not wndw Is Nothing Then If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End If End Sub "keiji kounoike" <"kounoike AT mbh.nifty.com" wrote in message ... I understand what you are saying at last, but is this usual way of using add-in? How can i use this macro in this case? I think i need to write some macro to add a menu to use this macro into Workbook_Open procedure. Keiji Jacob Skaria wrote: Try saving a workbook as .xla and open it. From VBE check out your project explorer. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Even if that macro is within an Add-in, Is there a situation that there is no workbook and no active window? if there is such a situation, that macro surely would fails. but i can't imagine such a situation. Keiji Jacob Skaria wrote: It can even be a procedure within an Add-In.. GavinS '"Nope, pasted that before the first line of code and it returns an error" As mentioned above you should not be pasting the below code to the other procedure. The procedure itself is re-written to suit your requirement. So try with the new procedure. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Then, How can you run the macro? Keiji Patrick Molloy wrote: if there's no workbook open (1) where would you put the code and (2) print / print preview isn't available "GavinS" wrote in message ... I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
How to Write Error Trap
the code checks to see if there is a workbook open before attempting to
toggle the print view --- as per your question - this thread "keiji kounoike" <"kounoike AT mbh.nifty.com" wrote in message ... Hi Patrick I can't get it why you post the code below to my post. Keiji Patrick Molloy wrote: Option Explicit Sub TogglePrintView() Dim wndw As Window Set wndw = ActiveWindow If Not wndw Is Nothing Then If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End If End Sub "keiji kounoike" <"kounoike AT mbh.nifty.com" wrote in message ... I understand what you are saying at last, but is this usual way of using add-in? How can i use this macro in this case? I think i need to write some macro to add a menu to use this macro into Workbook_Open procedure. Keiji Jacob Skaria wrote: Try saving a workbook as .xla and open it. From VBE check out your project explorer. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Even if that macro is within an Add-in, Is there a situation that there is no workbook and no active window? if there is such a situation, that macro surely would fails. but i can't imagine such a situation. Keiji Jacob Skaria wrote: It can even be a procedure within an Add-In.. GavinS '"Nope, pasted that before the first line of code and it returns an error" As mentioned above you should not be pasting the below code to the other procedure. The procedure itself is re-written to suit your requirement. So try with the new procedure. If this post helps click Yes --------------- Jacob Skaria "keiji kounoike" <"kounoike AT mbh.nifty." wrote: Then, How can you run the macro? Keiji Patrick Molloy wrote: if there's no workbook open (1) where would you put the code and (2) print / print preview isn't available "GavinS" wrote in message ... I have the following code to toggle between print preview and normal view but I need to add an error statement just in case there is no sheet open. Can someone please suggest how I might write this. Thanks Sub TogglePrintView() If ActiveWindow.View = xlPageBreakPreview Then ActiveWindow.View = xlNormalView ElseIf ActiveWindow.View = xlNormalView Then ActiveWindow.View = xlPageBreakPreview End If End Sub |
All times are GMT +1. The time now is 02:54 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com