• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Active Window View as Variable in Module

bkanne

Member
Would someone please be able to help me integrate the active window view as a variable into the code below?

Effectively, I'm trying to integrate the following logic at the beginning (and later end) of the code:
  1. Store the current view of the active sheet as a variable (i.e. xlPageBreakPreview)
  2. Change the view to normal view (xlNormalView)
  3. Run instructions from the code
  4. Last instruction - reset the view to the original stored variable
Obviously, if the view mode is already in NormalView, I'd like to be protected from any errors breaking the commands.

Thank you so much!
BK

Code:
Sub PasteAsPicture()

Application.DisplayCommentIndicator = xlNoIndicator
Application.DisplayAlerts = False
Set origSht = ActiveSheet
ActiveSheet.Copy after:=Sheets(Sheets.Count)
Set NewSht = ActiveSheet

For Each cll In Selection.Cells
  With cll.Font
    If .Color <> 16777215 Then .Color = -16777216
     End With
Next

Selection.Copy
Application.GoTo origSht.Range("A1")
ActiveSheet.Pictures.Paste
ActiveSheet.Pictures(ActiveSheet.Pictures.Count).Copy
Application.DisplayAlerts = False: NewSht.Delete: Application.DisplayAlerts = True
Application.DisplayCommentIndicator = xlCommentIndicatorOnly
ActiveSheet.Pictures(ActiveSheet.Pictures.Count).Delete
Application.DisplayAlerts = True

End Sub
 
Pls see the un-indented code below

Code:
Sub PasteAsPicture()

Dim awv As Integer
awv = ActiveWindow.View
ActiveWindow.View = xlNormalView

    Application.DisplayCommentIndicator = xlNoIndicator
    Application.DisplayAlerts = False
    Set origSht = ActiveSheet
    ActiveSheet.Copy after:=Sheets(Sheets.Count)
    Set NewSht = ActiveSheet
  
    For Each cll In Selection.Cells
      With cll.Font
        If .Color <> 16777215 Then .Color = -16777216
        End With
    Next
  
    Selection.Copy
    Application.GoTo origSht.Range("A1")
    ActiveSheet.Pictures.Paste
    ActiveSheet.Pictures(ActiveSheet.Pictures.Count).Copy
    Application.DisplayAlerts = False: NewSht.Delete: Application.DisplayAlerts = True
    Application.DisplayCommentIndicator = xlCommentIndicatorOnly
    ActiveSheet.Pictures(ActiveSheet.Pictures.Count).Delete
    Application.DisplayAlerts = True

ActiveWindow.View = awv

End Sub
 
Back
Top