クラスモジュールを使用して、保存ボタンのコレクションをすべて同じようにしています。しかし、変数を必要とするサブを実行させようとすると、変数を渡すことができません。クラスモジュールでどのようにパブリック変数を使用しますか?
@ Teaselのプロパティに関するアドバイスを使用して編集されました。この問題は、Let PropertyがModule1から変数を設定することを許可していないようです。
Class1の
Public WithEvents SaveBtn As MSForms.CommandButton
Dim currentrow As Long
Private Sub SaveBtn_Click()
SendMessage
`Even if I just have it Msgbox currentrow it returns 0
End Sub
Property Let GetRow(myrow As Long)
currentrow = myrow
End Property
Property Get GetRow() As Long
GetRow = currentrow
End Property
Module1の
`Trying to send the value into the Class using Let
Private Sub SendRow_Click()
Module1.GetRow = 22
End Sub
`Trying to Get the value back from the Class
Public Sub SendMessage()
Dim therow As Long
therow = Module1.GetRow
`I get the "Method or Data Member not found" error in the line above
MsgBox therow
End Sub
UserForm1で
`This part works fine
Dim colSaveButtons As New Collection
Private Sub UserForm_Initialize()
Dim i As Long
Dim ctl As MSForms.Control
Dim obEvents As Class1
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.CommandButton Then
For i = 0 To 5
If ctl.Name = "btnSavePage" & i Then
Set obEvents = New Class1
Set obEvents.SaveBtn = ctl
colSaveButtons.Add obEvents
End If
Next
End If
Next ctl
End Sub
問題を再現するために必要なコードのすべての部分を投稿してください。 [MCVE](https://stackoverflow.com/help/mcve)をチェックしてください。 – omegastripes
何も出力したり返したりするコードはありませんか? –
あなたはかなりの量のコードを与えてくれました。私が言うことは、 'GenericSave'への引数である' var'をブール値として定義したことです。論理的な真偽以外のものを渡そうとすると、期待していない結果が得られます。 –