I know very little about VBA and don't use it on a regular basis to learn much. I normally find code from a Google search, paste it in and modify it to fit my needs. Below simply inserts code from a module to an existing worksheet.
'This inserts code from a module to an existing worksheet
Sub Sample()
Dim wb As Workbook, ws As Worksheet
Dim strProcName As String
Set wb = ThisWorkbook
Set ws = Sheet1
Set VBP = wb.VBProject
strProcName = "Worksheet_SelectionChange"
With wb.VBProject.VBComponents( _
wb.Worksheets(ws.Name).CodeName).CodeModule
.InsertLines Line:=.CreateEventProc("SelectionChange", "Worksheet") + 1, _
String:=vbCrLf & _
" Msgbox ""Hello World"""
End With
End Sub
I don't want any cell to show a message box saying "Hello World"!
Below is the code I found that if pasted into my existing worksheet, does what I actually want. How can I get this to run within the macro above?
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("F5:J999")) Is Nothing Then
Cancel = True
Target.Formula = Date
End If
End Sub
Thanks in advance for anyone willing to give this your time.
'This inserts code from a module to an existing worksheet
Sub Sample()
Dim wb As Workbook, ws As Worksheet
Dim strProcName As String
Set wb = ThisWorkbook
Set ws = Sheet1
Set VBP = wb.VBProject
strProcName = "Worksheet_SelectionChange"
With wb.VBProject.VBComponents( _
wb.Worksheets(ws.Name).CodeName).CodeModule
.InsertLines Line:=.CreateEventProc("SelectionChange", "Worksheet") + 1, _
String:=vbCrLf & _
" Msgbox ""Hello World"""
End With
End Sub
I don't want any cell to show a message box saying "Hello World"!
Below is the code I found that if pasted into my existing worksheet, does what I actually want. How can I get this to run within the macro above?
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("F5:J999")) Is Nothing Then
Cancel = True
Target.Formula = Date
End If
End Sub
Thanks in advance for anyone willing to give this your time.