How to put the VBA code contained in code module in sheet module

How to put the VBA code contained in code module in sheet module



I have a button in the "code module" which runs a request. Next to the Button is a label included which shows a check mark a soon as the button has finished running.



The button code is in the code modul. The codes for the label with the check mark is inlcuded in the workbook and sheet modul.



Now, the issue is when I push the button it runs perfectly fine and does what it supposed to but the label with the check mark does not get activated. The reason might be because I have not included/referenced the workbook/sheet modul in my code modul. Hope for a bit help.



enter image description here



Code in workbook Module:


Option Explicit
Private Sub Workbook_Open()
Call Tabelle1.prcResetLabels
End Sub



Code in Sheet Module:


Option Explicit

Private Sub Schaltfläche2_Klicken()
Call prcSetLabel(probjLabel:=Label1)
End Sub

Private Sub prcSetLabel(ByRef probjLabel As MSForms.Label)
With probjLabel
.Caption = "P"
End With
End Sub

Friend Sub prcResetLabels()
Dim objOLEObject As OLEObject
For Each objOLEObject In OLEObjects
With objOLEObject
If .progID = "Forms.Label.1" Then _
.Object.Caption = vbNullString
End With
Next
End Sub



Code in Codemodul:


Public Sub Schaltfläche2_Klicken()
With Sheets("Table1")
.Range("A1").End(xlUp).Offset(1, 0).Value = Environ("USERNAME")
End With
End Sub





Declare your module sub as public. Also, what is Friend Sub?
– QHarr
Sep 5 '18 at 8:45





The Freind Sub is the code to clear all check marks afterwards. I have renamed "Private" to " Public" in the code modul but the sheet module still doesnt get activated.
– Yavuz Topal
Sep 5 '18 at 8:55





OK.. I am very sorry to be this guy but I have no idea what your issue is. Please make sure that in the problem description the current behaviour and the desired behaviour is clearly distinguishable and that the problem is clear. A problem is always the difference between desired and current behaviour.
– Lucas Raphael Pianegonda
Sep 5 '18 at 9:16





What do you mean by activated? And prefix the sub with the module name.
– QHarr
Sep 5 '18 at 9:22





Thanks to Lucas Raphael Pianegonda i have rephrased the the porblem a bit. By activated I mean when the button is pushed the label (which is reponsible for the check mark) doesnt run as the link between the codemodul for the button and the sheet modul for the label is missing perhaps.
– Yavuz Topal
Sep 5 '18 at 9:33




1 Answer
1



The answer ist simple this:


Sub Schaltfläche2_Klicken()
Call prcResetLabels
With Sheets("Table1")
.Range("A1").End(xlUp).Offset(1, 0).Value = Environ("USERNAME")
End With
Call prcSetLabel(probjLabel:=Table1.Label1)
End Sub

Private Sub prcSetLabel(ByVal probjLabel As Object)
With probjLabel
.Object.Caption = "P"
End With
End Sub
Public Sub prcResetLabels()
Dim objOLEObject As OLEObject

For Each objOLEObject In Table1.OLEObjects
With objOLEObject
If .progID = "Forms.Label.1" Then _
.Object.Caption = vbNullString
End With
Next
End Sub



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ