我正在尝试组装一个宏来弹出一个对话框来选择您的打印机,然后打印具有特定属性的特定命名范围。我从一个可以正常工作的小测试语句开始。
Sub test()
' test Macro
Application.Dialogs(xlDialogPrinterSetup).Show
ActiveSheet.PageSetup.PrintArea = "Print_20_Year"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
End Sub
然后我搬进了更大的枪,我无法让它正常工作。我将 包含MsgBox
在宏中以查看是否有任何项目正在触发。
没有错误,没有MsgBox
弹出窗口。有什么想法吗?
编辑这是我的新代码和当前代码。它工作正常,一旦我取消对 printrowtiles 的注释,它就会中断。这是它直接从录制宏中给出的代码。
Sub Print_20_Year()
'
' Print_20_Year Macro
'
'
'
' Range("Print_20_Year").Select
MsgBox "Step .4"
Application.Dialogs(xlDialogPrinterSetup).Show
MsgBox "Step .6"
Application.PrintCommunication = False
MsgBox "Step .7"
' With ActiveSheet.PageSetup
' .PrintTitleRows = "$4:$13"
MsgBox "Step .8"
' .PrintTitleColumns = ""
' End With
MsgBox "Step .9"
Application.PrintCommunication = True
MsgBox "Step 1"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.HeaderMargin = Application.InchesToPoints(0)
.FooterMargin = Application.InchesToPoints(0)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperTabloid
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = False
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
MsgBox "Step 2"
ActiveSheet.PageSetup.PrintArea = "Print_20_Year"
MsgBox "Step 3"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
End Sub