Excel Print的这行vba代码有什么问题 [英] what is wrong with this line of vba code for Excel Print
问题描述
我在Excel中有一个带有页面大小列表的组合框.我想通过组合框选择更改来更改页面大小.
I have a combobox with list of page size in excel. i want to change page sizes with combobox selection change.
以下操作无效
Public Sub UpdateSize()
Dim Papersizetext As String
Papersizetext = "xlPaper" & Worksheets("Static").Range("B7").value 'A4 is the value in cell B7
shgenerate.PageSetup.PaperSize = Papersizetext 'not working
shgenerate.PageSetup.PaperSize = "xlPaper" & Combobox1.value 'this also not working
shgenerate.PageSetup.PaperSize = xlPaperA4 'is working - i want above to work.
'shgenerate is sheet name
End sub
推荐答案
您可以启动自己的函数来解析输入并返回正确的枚举成员:
You could whip up your own function to parse the input and return the correct enum member:
Private Function PaperSize(ByVal rawSize As String) As Long
Select Case rawSize
Case "A4"
PaperSize = xlPaperA4
Case "A3"
PaperSize = xlPaperA3
Case "A5"
PaperSize = xlPaperA5
Case Else
PaperSize = xlPaperUser ' or some other default
End Select
End Function
对于更复杂的纸张尺寸,例如"Letter 8.5" x11"22x28cm"
或"Legal 8.5" x14"22x36cm"
,您可以使用InStr
测试"Letter"和"Legal"的存在,以返回 xlPaperLetter
和 xlPaperLegal
.
For more complex paper sizes, such as "Letter 8.5"x11" 22x28cm"
or "Legal 8.5"x14" 22x36cm"
, you could possibly use InStr
to test of the existence of "Letter" and "Legal" to return xlPaperLetter
and xlPaperLegal
.
正则表达式可能是解析尺寸的另一种方法.
Regex might be another approach to parse out the dimensions.
尽管没有更多细节,但是很难给出令人满意的答案,因为这个问题实际上是一个广泛的话题.
Without more detail though, it's hard to give a satisfactory answer, as this question is actually quite a broad topic.
这篇关于Excel Print的这行vba代码有什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!