A
ajvasel
In the program that I am working on, I copy and paste filtered data into a
new workbook multiple times. Each time that I complete this procedure, I set
the print preview to be set up a certain way. In order to be able to get out
of the print preview screen, I used SendKeys to click through it. When I run
just the sub for 1 instance of creating the new workbook, copying and pasting
the filtered data, etc., it works fine; but when I run the entire program and
it gets to the print preview screen, the SendKeys statement doesn't work. I
discovered that something causes the active screen to be inactive because if
I manually press Alt and C, nothing happens.
So, my question is, what can cause the screen to become inactive that would
cause SendKeys to not work? and what can I do to rectify this? thanks
This is the individual part that works fine by itself
Sub File1000()
Selection.AutoFilter Field:=2, Criteria1:="1000"
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Columns("A:G").Select
Selection.Columns.AutoFit
Columns("H:V").Select
Selection.ColumnWidth = 10
With ActiveSheet.PageSetup
.PrintTitleRows = "$4:$4"
.PrintTitleColumns = ""
End With
Range("A4").Select
Sheets(Array("Sheet2", "Sheet3")).Select
Sheets("Sheet3").Activate
Application.CutCopyMode = False
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "1000"
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = "Page &P of &N"
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0)
.RightMargin = Application.InchesToPoints(0)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLegal
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 70
.PrintErrors = xlPrintErrorsDisplayed
End With
Application.SendKeys ("{%}c")
ActiveWindow.SelectedSheets.PrintPreview
Range("E2").Select
End Sub
new workbook multiple times. Each time that I complete this procedure, I set
the print preview to be set up a certain way. In order to be able to get out
of the print preview screen, I used SendKeys to click through it. When I run
just the sub for 1 instance of creating the new workbook, copying and pasting
the filtered data, etc., it works fine; but when I run the entire program and
it gets to the print preview screen, the SendKeys statement doesn't work. I
discovered that something causes the active screen to be inactive because if
I manually press Alt and C, nothing happens.
So, my question is, what can cause the screen to become inactive that would
cause SendKeys to not work? and what can I do to rectify this? thanks
This is the individual part that works fine by itself
Sub File1000()
Selection.AutoFilter Field:=2, Criteria1:="1000"
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Columns("A:G").Select
Selection.Columns.AutoFit
Columns("H:V").Select
Selection.ColumnWidth = 10
With ActiveSheet.PageSetup
.PrintTitleRows = "$4:$4"
.PrintTitleColumns = ""
End With
Range("A4").Select
Sheets(Array("Sheet2", "Sheet3")).Select
Sheets("Sheet3").Activate
Application.CutCopyMode = False
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "1000"
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = "Page &P of &N"
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0)
.RightMargin = Application.InchesToPoints(0)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLegal
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 70
.PrintErrors = xlPrintErrorsDisplayed
End With
Application.SendKeys ("{%}c")
ActiveWindow.SelectedSheets.PrintPreview
Range("E2").Select
End Sub