1

每当用户通过 VBA 代码打印时,我想将访问报告纸张尺寸永久设置为 A3。为此,我编写了我在网上找到的这段代码

Option Compare Database

Type gtypStr_DEVMODE
    RGB As String * 94
End Type

Type gType_DEVMODE
    strDeviceName As String * 32
    intSpecVersion As Integer
    intDriverVersion As Integer
    intSize As Integer
    intDriverExtra As Integer
    lngFields As Long
    intOrientation As Integer
    intPaperSize As Integer
    intPaperLength As Integer
    intPaperWidth As Integer
    intScale As Integer
    intCopies As Integer
    intDefaultSource As Integer
    intPrintQuality As Integer
    intColor As Integer

    intDuplex As Integer
    intResolution As Integer
    intTTOption As Integer
    intCollate As Integer
    strFormName As String * 32
    lngPad As Long
    lngBits As Long
    lngPW As Long
    lngPH As Long
    lngDFI As Long
    lngDFr As Long
End Type

Sub SetToA3(pReport As String)

    Dim LDevString As gtypStr_DEVMODE
    Dim LDM As gType_DEVMODE
    Dim LDevModeExtra As String
    Dim LRpt As Report

    On Error GoTo Err_Execute

    'Open report in Design view
    DoCmd.OpenReport pReport, acDesign
    Set LRpt = Reports(pReport)

    'Change paper size to legal
    If Not IsNull(LRpt.PrtDevMode) Then

        LDevModeExtra = LRpt.PrtDevMode
        LDevString.RGB = LDevModeExtra
        LSet LDM = LDevString

        '5=legal, 1=standard
        LDM.intPaperSize = 256
        LSet LDevString = LDM
        Mid(LDevModeExtra, 1, 94) = LDevString.RGB
        LRpt.PrtDevMode = LDevModeExtra

    End If

    'Save report changes (suppress system messages temporarily)
    DoCmd.SetWarnings False
    DoCmd.Save acReport, pReport
    DoCmd.Close acReport, pReport
    DoCmd.SetWarnings True

    Exit Sub

Err_Execute:
    MsgBox "Changing paper size to legal failed."
End Sub

但它根本不起作用,即当我调用 SettoA3 程序时,什么也没有发生。

为什么不?

4

1 回答 1

0

好吧...我不相信您自己编写了该代码(指向您发现它的位置的链接会很有帮助,我发现了大约 20 条引用)但您可能想更改LDM.intPaperSize = 256LDM.intPaperSize = acPRPSA3.

我在MS 的页面上找到了这个(它隐藏在 AcPrintPaperSize 的下拉列表中

于 2011-06-03T18:39:50.587 回答