chroniclesofdave
New Member
- Joined
- Aug 8, 2016
- Messages
- 48
So i have a second userform that launches from the first, and in the second i use a bit of code as seen here
and this codes intent is to overwrite a bit of code in Module1. Everything works fine, but when i run the code and then click the command button with
or
or even
it always hides userform1 as well. maybe it isn't actually hidden, but it is no longer visible, and i cannot locate it on my screen. if i do not run the above code and click the button, everything works fine, but once the code has run, it starts to act up. i have trolled through forum posts both here, MS forums, and everywhere i can, but i have had no success. any ideas?
Code:
Private Sub CommandButton66_Click() Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim StartLine As Long
Dim NumLines As Long
Dim ProcName As String
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("Module1")
Set CodeMod = VBComp.CodeModule
ProcName = "Button1"
With CodeMod
StartLine = .ProcStartLine(ProcName, vbext_pk_Proc)
NumLines = .ProcCountLines(ProcName, vbext_pk_Proc)
.DeleteLines StartLine:=StartLine, Count:=NumLines
End With
StartAdd
End Sub
Sub StartAdd()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = ActiveWorkbook.VBProject.VBComponents("Module1")
AddProcedureToModule
End Sub
Sub AddProcedureToModule()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long
Const DQUOTE = """" ' one " character
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("Module1")
Set CodeMod = VBComp.CodeModule
With CodeMod
LineNum = .CountOfLines + 1
.InsertLines LineNum, "Public Sub Button1()"
LineNum = LineNum + 1
.InsertLines LineNum, "Dim obj As New DataObject"
LineNum = LineNum + 1
.InsertLines LineNum, "Dim txt As String"
LineNum = LineNum + 1
.InsertLines LineNum, "'Put some text inside a string variable"
LineNum = LineNum + 1
.InsertLines LineNum, "txt = " & DQUOTE & TextBox1.Value & DQUOTE
LineNum = LineNum + 1
.InsertLines LineNum, "'Make object's text equal above string variable"
LineNum = LineNum + 1
.InsertLines LineNum, "obj.SetText txt"
LineNum = LineNum + 1
.InsertLines LineNum, "'Place DataObject's text into the Clipboard"
LineNum = LineNum + 1
.InsertLines LineNum, "obj.PutInClipboard"
LineNum = LineNum + 1
.InsertLines LineNum, "End Sub"
LineNum = LineNum + 1
End With
End Sub
and this codes intent is to overwrite a bit of code in Module1. Everything works fine, but when i run the code and then click the command button with
Code:
unload me
Code:
unload userform8
Code:
userform8.hide