Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default 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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default 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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default 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


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default 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


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default 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


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default 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





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default 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

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default 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

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default 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


  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default 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

  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default 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



  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default 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

  #19   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default 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

  #20   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default 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


  #21   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default 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
  #22   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default 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

  #23   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default 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


  #24   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default 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


  #25   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set Error handling INSIDE error-trap Michelle Excel Programming 6 May 3rd 08 03:30 PM
Need error trap GregR Excel Programming 4 June 14th 07 08:28 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Error Trap TEB2 Excel Programming 2 March 15th 05 05:34 PM
error trap Rhonda[_3_] Excel Programming 2 October 22nd 03 07:07 PM


All times are GMT +1. The time now is 02:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"