Excel VBA Application.PrintCommunication不再使用网络打印机

问题描述 投票:0回答:1

我总是在过去找到我的答案,所以我希望你们中的一个天才可以为我拉一个伎俩。这是情况。几年前我在Excel 2016中创建了一个小应用程序。它已经运行了2年,现在完美无瑕。我不得不说这是我以前的工作(但我仍然在这里做售后服务......)。无论如何,最近他们搬到Office 365然后kaboom!他们无法使用打印创建的报告的功能。错误是

运行时错误1004对象'_Application'的方法'PrintCommunication'失败

请记住,在他们切换到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

那么任何人,任何好主意和解决方案?如果我对问题的解释不明确,请不要犹豫。

非常感谢你提前。

excel vba excel-vba
1个回答
1
投票

该错误是由该行引起的

.Zoom = False

通过VBA设置“缩放”属性时,如果要使用缩放方法控制缩放,则必须将.Zoom =整数值设置在10到400之间(例如,.Zoom = 25)。该值通过Excel转换为百分比(例如,10%至400%),然后用作乘数。

如果要控制宽和高的页数,请使用属性.FitToPagesWide = some Integer.FitToPagesTall = some Integer

如果使用.FitTo... properties,则.Zoom由Excel设置为false而不是VBA代码。这是MS文档的链接,解释了.Zoom属性的使用。

因此,您需要删除或注释掉.Zoom = False行或两行

.FitToPagesWide = 1
.FitToPagesTall = 0
© www.soinside.com 2019 - 2024. All rights reserved.