【问题标题】:change excel page size with combobox selection change使用组合框选择更改更改 excel 页面大小
【发布时间】:2020-04-17 12:59:13
【问题描述】:

我在“windows 打印服务器属性”下为 excel 创建了一个自定义页面大小。按照此处给出的步骤https://www.win2pdf.com/doc/pdf-custom-paper-windows-10.html

现在我有了所有自定义尺寸,包括 excel 页面尺寸列表中显示的默认尺寸。接下来,我使用以下代码将所有尺寸拉到 excel Combobox 下拉列表中。

所以我的要求是通过组合框选择更改来更改 excel 表大小。

请注意:除非尺寸是固定的,否则我们不能使用 case 方法更改尺寸或预定义它,因为尺寸在 Combobox 中是动态的,一旦用户创建了新尺寸,它将被添加到 Combobox。

谢谢

'worksheet code
        ActiveSheet.ComboBox1.List = GetPaperSizes

'模块代码

    Option Explicit

    Private Const DC_PAPERNAMES = &H10

    Private Declare Function DeviceCapabilities _
      Lib "winspool.drv" _
        Alias "DeviceCapabilitiesA" _
          (ByVal lpDeviceName As String, _
           ByVal lpPort As String, _
           ByVal iIndex As Long, _
           ByRef lpOutput As Any, _
           ByRef lpDevMode As Any) _
        As Long

    Private Declare Function StrLen _
      Lib "kernel32.dll" _
        Alias "lstrlenA" _
          (ByVal lpString As String) _
        As Long

    Function GetPaperSizes() As Variant

        Dim AllNames As String
        Dim I As Long
        Dim Msg As String
        Dim PD As Variant
        Dim Ret As Long
        Dim papersizes() As Byte
        Dim PaperSize As String

        'Retrieve the number of available paper names
        PD = Split(Application.ActivePrinter, " on ")'<<<== change "on" with its local Language translation from english
        Ret = DeviceCapabilities(PD(0), PD(1), DC_PAPERNAMES, ByVal 0&, ByVal 0&)

        'resize the array
        ReDim papersizes(0 To Ret * 64) As Byte

        'retrieve all the available paper names
        Call DeviceCapabilities(PD(0), PD(1), DC_PAPERNAMES, papersizes(0), ByVal 0&)

        'convert the retrieved byte array to an ANSI string
        AllNames = StrConv(papersizes, vbUnicode)

         'loop through the string and search for the names of the papers
        For I = 1 To Len(AllNames) Step 64
            PaperSize = Mid(AllNames, I, 64)
            PaperSize = Left(PaperSize, StrLen(PaperSize))
            If PaperSize <> vbNullString Then Msg = Msg & PaperSize & vbCrLf
        Next I

        GetPaperSizes = Split(Left(Msg, Len(Msg) - 2), vbCrLf)

    End Function

【问题讨论】:

    标签: excel vba windows printing


    【解决方案1】:

    我可以期待任何帮助吗?我不确定这个颠簸是否正确。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-25
      相关资源
      最近更新 更多