我过去一直在这里找到我的答案,所以我希望你们中的一个天才能为我再耍一个小把戏。情况就是这样。几年前,我在Excel 2016中创建了一个小应用程序。它已经运行了两年,现在已经完美无缺了。我不得不说,这是我以前的工作(但我仍然在这里做某种售后服务.)。不管怎么说,他们最近搬到办公室365,然后卡波姆!他们不能使用打印创建的报表的功能。错误是
运行时错误1004对象'PrintCommunication‘的方法'_Application’失败
请记住,在切换到Office 365之前。一切都很顺利。
此外,您必须知道,如果您使用本地打印机(插入USB电缆),它的工作完美(就像以前一样)。该方法(本地打印机)在2台计算机上进行了测试,运行良好。但如果它是公司里的网络打印机,那就行不通了。
编辑:我刚刚发现它在公司的某些地方起作用,而不是在一个地方。例如,它适用于所有省份的员工(我们在加拿大:各省相当于美国的州),但只有一个省除外。因此,一定有一些与服务器上的参数不兼容的东西,或者类似的东西。对别人有帮助吗?编辑结束
我看过这里和其他地点。我已经试过了很多关于“注释掉”行的技巧,比如“打印质量= 600”之类的东西。
下面是密码。错误在直线上
Application.PrintCommunication = True
"End Sub"
前4行。另一行,当我切换.printCommunication = True
时,没有错误
Sub imprime_feuille_identification(trois_feuille)
'
Sheets("IDENTIFICATION").Activate
ActiveWorkbook.Worksheets("MOYENS_CONTROLE").Cells(9, 16384) = ActiveSheet.Name 'identifie de quelle feuille vient la demande d'impression sert à y revenir ensuite
ActiveWorkbook.Worksheets("MOYENS_CONTROLE").Cells(10, 16384) = "" 'va servir à identifier qu'on veut imprimer une seule feuille
Range("A1:P38").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$P$38" 'définition de la zone d'impression
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = "$2:$2"
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = "$A$1:$P$38"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = " &9&P de &N "
.LeftMargin = Application.InchesToPoints(9.84251968503937E-02)
.RightMargin = Application.InchesToPoints(9.84251968503937E-02)
.TopMargin = Application.InchesToPoints(9.84251968503937E-02)
.BottomMargin = Application.InchesToPoints(9.84251968503937E-02)
.HeaderMargin = Application.InchesToPoints(0.196850393700787)
.FooterMargin = Application.InchesToPoints(0.196850393700787)
.PrintHeadings = False
.PrintGridlines = False
'.PrintComments = xlPrintNoComments
'.PrintComments = False 'xlPrintNoComments
.PrintQuality = 600 'Tried to comment out this line: still get the error
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 0
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.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 'THE ERROR HAPPENS HERE'
If trois_feuille <> 1 Then 'si le sub a été appelé en dehors du sub "imprime trois feuille" alors on fait
Application.CommandBars.ExecuteMso ("PrintPreviewAndPrint") 'affiche la page d'impression
End If
End Sub
有谁有聪明的想法和解决方案吗?如果我对这个问题的解释不清楚,请不要犹豫。
先谢谢你。
发布于 2017-12-19 15:44:01
错误是由行引起的。
.Zoom = False
当通过VBA设置Zoom属性时,如果要使用缩放方法控制缩放,必须将.Zoom =整数值设置在10到400之间(例如,.Zoom = 25
)。该值由Excel转换为百分比(例如,10%至400%),然后用作乘数。
如果您想要控制宽度和高度的页数,那么使用属性.FitToPagesWide = some Integer
和.FitToPagesTall = some Integer
。
如果您使用的是.FitTo... properties
,那么.Zoom就会被.Zoom设置为false,而不是VBA代码。这里有一个指向MS文档的链接,用于解释.Zoom属性的使用。
因此,您需要删除或注释掉.Zoom = False
行或两行
.FitToPagesWide = 1
.FitToPagesTall = 0
https://stackoverflow.com/questions/47889751
复制相似问题