用组合框选择改变excel页面大小。

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

我在 "windows打印服务器属性 "下为excel创建了一个自定义页面大小。https:/www.win2pdf.comdocpdf-custom-paper-windows-10.html

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

所以我的要求是用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

enter image description here

excel vba windows printing
1个回答
0
投票

我可以期待任何帮助吗?我不知道这个撞击是否正确。

© www.soinside.com 2019 - 2024. All rights reserved.