我需要一些帮助来审查我的一些基本代码,因为有时它会返回“运行时错误”,而我对此感到迷茫。我有一个带有文本框的表单,当我填写第一个时,它会自动填充工作簿上隐藏的工作表下方的另外两个文本框,它有一个组合框,自动填充也使用该文件的其他 Windows 用户的用户名。 最终目标是从一行 2 页的文本框中打印两张填充的纸,打印机具有双面属性并将两张纸打印在一张纸的两面。
Private Sub comimprimirvas_prod_Click()
Dim irow As Long
Dim ws As Worksheet
Dim lvalue
lvalue = Now
Set ws = ThisWorkbook.Worksheets("Base Dados Vasilhame")
irow = ws.Cells(Rows.Count, 9).End(xlUp).Offset(1, 0).Row
With ws
.Range("A" & irow) = txtclienteopl.Value
.Range("B" & irow) = txtdevolução.Value
.Range("C" & irow) = txtlocaldecarga.Value
.Range("D" & irow) = txtmatricula2.Value
.Range("E" & irow) = txtpistacais.Value
.Range("F" & irow) = txtnºdevolução.Value
.Range("G" & irow) = txtundbarril.Value
.Range("H" & irow) = txtundgrade.Value
.Range("I" & irow) = lvalue
End With
'''''''''''''''''This inserts the username'''''''''''''''''''
Me.ComboBox1.Text = Environ$("Username")
ComboBox1.AddItem "André Lopes"
ComboBox1.AddItem "BackOffice"
ComboBox1.AddItem "Carlos Silva"
ComboBox1.AddItem "Flavio Gonçalves"
ComboBox1.AddItem "Nuno Prada"
ComboBox1.AddItem "Rita Vieira"
ComboBox1.AddItem "Zaida Sousa"
ComboBox1.AddItem ""
txtdevolução.SetFocus
''''''''''''''''This fills sheet Vasilhame''''''''''''''''''
With ThisWorkbook.Sheets("Vasilhame")
.Visible = True
.Range("AJ7:AL7") = txtclienteopl.Value
.Range("AJ14:AL14") = txtdevolução
.Range("AJ9:AL9") = txtlocaldecarga
.Range("AJ12:AL12") = txtmatricula2
.Range("AJ16:AL16") = txtpistacais
.Range("AJ19:AL19") = txtnºdevolução
.Range("AL21") = txtundbarril
.Range("AL22") = txtundgrade
End With
''''This fills sheet Devolução de produto'''''''''''''
With ThisWorkbook.Sheets("Devoluções de produto")
.Visible = True
.Range("AR9:AY9") = txtnºdevolução.Value
.Range("AR12:AY12") = txtclienteopl
.Range("AR15:AY15") = txtmatricula2
.Range("AR18:AY18") = txtpistacais
End With
With ThisWorkbook.Sheets(Array("Devoluções de produto", "Vasilhame"))
ThisWorkbook.Sheets(Array("Devoluções de produto", "Vasilhame")).Select
.PrintOut
ThisWorkbook.Sheets("Devoluções de produto").Range("AR9:AY9").ClearContents
ThisWorkbook.Sheets("Devoluções de produto").Range("AR12:AY12").ClearContents
ThisWorkbook.Sheets("Devoluções de produto").Range("AR15:AY15").ClearContents
ThisWorkbook.Sheets("Devoluções de produto").Range("AR18:AY18").ClearContents
ThisWorkbook.Sheets("Vasilhame").Range("AJ7:AL7").ClearContents
ThisWorkbook.Sheets("Vasilhame").Range("AJ9:AL9").ClearContents
ThisWorkbook.Sheets("Vasilhame").Range("AJ12:AL12").ClearContents
ThisWorkbook.Sheets("Vasilhame").Range("AJ14:AL14").ClearContents
ThisWorkbook.Sheets("Vasilhame").Range("AJ16:AL16").ClearContents
ThisWorkbook.Sheets("Vasilhame").Range("AJ19:AL19").ClearContents
ThisWorkbook.Sheets("Vasilhame").Range("AL21").ClearContents
ThisWorkbook.Sheets("Vasilhame").Range("AL22").ClearContents
txtnºdevolução = ""
txtclienteopl = ""
txtmatricula2 = ""
txtpistacais = ""
txtclienteopl = ""
txtdevolução = ""
txtlocaldecarga = ""
txtmatricula2 = ""
txtpistacais = ""
txtnºdevolução = ""
txtundbarril = ""
txtundgrade = ""
'''''''''''This changes the checkbox to X or blank'''''''''''''''''
ThisWorkbook.Worksheets("Vasilhame").Range("AA2").Value = CheckBox1_PC.Value
CheckBox1_PC.Value = ""
If CheckBox1_PC.Value = True Then
ThisWorkbook.Worksheets("Vasilhame").Range("AA2").Value = "X"
Else
ThisWorkbook.Worksheets("Vasilhame").Range("AA2").Value = ""
End If
''''''''''''''This changes the checkbox2 to X or blank''''''''''''''
ThisWorkbook.Worksheets("Vasilhame").Range("AG6").Value = CheckBox2_PC.Value
CheckBox2_PC.Value = ""
If CheckBox2_PC.Value = True Then
ThisWorkbook.Worksheets("Vasilhame").Range("AG6").Value = "X"
Else
ThisWorkbook.Worksheets("Vasilhame").Range("AG6").Value = ""
End If
ThisWorkbook.Worksheets("Vasilhame").Range("AC2:AG2").Value = ComboBox1.Value
ComboBox1.Value = ""
If ComboBox1.Value = True Then
ThisWorkbook.Worksheets("Vasilhame").Range("AC2:AG2").Value = ComboBox1.Value
End If
.Visible = False
End With
end sub
我在这部分遇到了一些问题,但我并不总是这样。
ThisWorkbook.Sheets(Array("Devoluções de produto", "Vasilhame")).Select"