[英]Print Multiple Sheet from User Input Using Excel VBA
I have a code which will take user input from a list box, which is the name of all the tabs I have in the workbook, selected name will be moved to another listbox, say Listbox2. 我有一个代码,它将从列表框中获取用户输入,这是我在工作簿中的所有选项卡的名称,所选名称将被移动到另一个列表框,比如Listbox2。 This list box 2 items are being converted to an array to go to the print preview page.
此列表框中的2个项目正在转换为数组以转到打印预览页面。 but the problem is, I'm doing it in a loop, so I can't print them in one go.
但问题是,我是在循环中进行的,所以我不能一次打印它们。 If I select 5 tabs, I'm having to print 5 tabs separately.
如果我选择5个标签,则必须分别打印5个标签。 I want to print them together.
我想把它们一起打印出来。 I've tried putting the print preview command out of the loop, but then I get an error saying application not found or something similar.
我已经尝试将打印预览命令放在循环之外,但后来我收到一个错误,说找不到应用程序或类似的东西。 Here's the code below:
这是下面的代码:
Private Sub Printout1_Click()
Dim Size As Integer
Size = Me.ListBox2.ListCount - 1
ReDim ListBoxContents(0 To Size) As String
Dim i As Integer
For i = 0 To Size
ListBoxContents(i) = Me.ListBox2.List(i)
Next i
For i = 0 To Size
Sheets(ListBoxContents(i)).Visible = True
Sheets(ListBoxContents(i)).Select
ActiveWindow.SelectedSheets.PrintPreview
Sheets(ListBoxContents(i)).Visible = False
Next i
End Sub
You can copy all the sheets in another sheet just for print , For exemple if he select sheet1 and sheet2 您可以复制另一张纸中的所有纸张仅用于打印,例如,如果他选择了sheet1和sheet2
You can use a sheet called PRINTSHEET 您可以使用名为PRINTSHEET的工作表
and them Copy the Sheet1.usedrange and Sheet2.usedrange to PrintSheet 然后将Sheet1.usedrange和Sheet2.usedrange复制到PrintSheet
after that u can just print the PrintSheet 之后你可以打印PrintSheet
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.