sassora
05-19-2012, 02:21 AM
Hi all,
I have some code that I want to run when the excel file opens.
The VBA below works fine but I'd like to put the bulk of the code in its own sub.
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Set shWorkitems = Sheets("Job List")
Set shFolderitems = Sheets("Folder Search")
Select Case Sh.Name
Case shWorkitems.Name
If Target.Column = 10 Then
On Error Resume Next
Application.Goto shFolderitems.Range("A" & Application.Match(Target.Value, _
shFolderitems.Columns(11), 0)), True
Cancel = True
ElseIf Target.Column = 9 Then
Call MainUpdateFolderLog
Cancel = True
End If
Case shFolderitems.Name
If Target.Column = 1 Then
On Error Resume Next
Application.Goto shWorkitems.Range("A" & Application.Match(Target.Offset(0, 10).Value, _
shWorkitems.Columns(10), 0)), True
Cancel = True
End If
End Select
End Sub
The alternative code would look like:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Call RunOnOpenCode
End sub
How would I do this?
I have some code that I want to run when the excel file opens.
The VBA below works fine but I'd like to put the bulk of the code in its own sub.
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Set shWorkitems = Sheets("Job List")
Set shFolderitems = Sheets("Folder Search")
Select Case Sh.Name
Case shWorkitems.Name
If Target.Column = 10 Then
On Error Resume Next
Application.Goto shFolderitems.Range("A" & Application.Match(Target.Value, _
shFolderitems.Columns(11), 0)), True
Cancel = True
ElseIf Target.Column = 9 Then
Call MainUpdateFolderLog
Cancel = True
End If
Case shFolderitems.Name
If Target.Column = 1 Then
On Error Resume Next
Application.Goto shWorkitems.Range("A" & Application.Match(Target.Offset(0, 10).Value, _
shWorkitems.Columns(10), 0)), True
Cancel = True
End If
End Select
End Sub
The alternative code would look like:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Call RunOnOpenCode
End sub
How would I do this?