N
natanz
I have an application that i am working on that has many userforms. at
the bottom of the userform there is one commandbutton, and i want all
the userforms to do the same procedure when that command button is
clicked.
here is the code:
Public Sub pg_finish()
Dim ctl As Control
Dim count As Integer
Dim fname As String
On Error Resume Next
fname = Environ("temp") & "\PG " & ActiveCell.Value & ".xls"
count = 3
ActiveCell.Offset(0, 1).Value = "sold"
For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
ActiveCell.Offset(0, count).Value = ctl.Name & ": " &
ctl.Value
count = count + 1
End If
Next ctl
ActiveCell.Offset(0, count).Value = "Total: " & TextBox1.Value
ActiveSheet.Copy
ActiveWorkbook.SaveAs fname
ActiveWorkbook.SendMail "(e-mail address removed)", fname
ActiveWorkbook.ChangeFileAccess xlReadOnly
ActiveWorkbook.Close
Kill fname
Application.Workbooks("dk design
macro.xls").Worksheets("sheet1").Activate
count = 0
Unload Me
End Sub
the code was working fine, when it was written in the code window of
the userform, but i tried to move it to a module, so that all the
userforms could refer to it, now the line that reads "For Each ctl In
Me.Controls" isn't working. I understand that me won't work, because
the code is not in the form's code window. how can i make that
reference more generic, so that it will work here.
thanks for any help.
the bottom of the userform there is one commandbutton, and i want all
the userforms to do the same procedure when that command button is
clicked.
here is the code:
Public Sub pg_finish()
Dim ctl As Control
Dim count As Integer
Dim fname As String
On Error Resume Next
fname = Environ("temp") & "\PG " & ActiveCell.Value & ".xls"
count = 3
ActiveCell.Offset(0, 1).Value = "sold"
For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
ActiveCell.Offset(0, count).Value = ctl.Name & ": " &
ctl.Value
count = count + 1
End If
Next ctl
ActiveCell.Offset(0, count).Value = "Total: " & TextBox1.Value
ActiveSheet.Copy
ActiveWorkbook.SaveAs fname
ActiveWorkbook.SendMail "(e-mail address removed)", fname
ActiveWorkbook.ChangeFileAccess xlReadOnly
ActiveWorkbook.Close
Kill fname
Application.Workbooks("dk design
macro.xls").Worksheets("sheet1").Activate
count = 0
Unload Me
End Sub
the code was working fine, when it was written in the code window of
the userform, but i tried to move it to a module, so that all the
userforms could refer to it, now the line that reads "For Each ctl In
Me.Controls" isn't working. I understand that me won't work, because
the code is not in the form's code window. how can i make that
reference more generic, so that it will work here.
thanks for any help.