Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#12
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#13
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#14
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#15
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#16
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#17
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#18
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#19
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#20
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
#21
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
#22
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#23
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#24
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#25
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Set Error handling INSIDE error-trap | Excel Programming | |||
Need error trap | Excel Programming | |||
Error Handling - On Error GoTo doesn't trap error successfully | Excel Programming | |||
Error Trap | Excel Programming | |||
error trap | Excel Programming |