ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   VBA Event (https://www.excelbanter.com/excel-discussion-misc-queries/206300-vba-event.html)

Steve

VBA Event
 
In my entire workbook, I want to be able to change of the font of a cell when
the cell has a hyperlink in it.
This VB works if you paste it in each worksheet:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Hyperlinks.Count = 1 Then Target.Select
With Selection.Font
.Color = -16776961
.TintAndShade = 0
End With


End Sub


but instead of pasting 100+ worksheets in the workbook, where should I place
this code?



--
Steve

Mike H

VBA Event
 
Steve,

The workbook-sheet change applies to all sheets.

Alt+F11 to open VB editor. Double click 'This workbook' and paste this in on
the right

Note I've commented out .tintshade because that doesn't work in 2003 in fact
i'm only assuming it works in another version, I've never heard of it

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Hyperlinks.Count = 1 Then Target.Select
With Selection.Font
.Color = -16776961
'.TintAndShade = 0
End With
End Sub

Mike

"Steve" wrote:

In my entire workbook, I want to be able to change of the font of a cell when
the cell has a hyperlink in it.
This VB works if you paste it in each worksheet:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Hyperlinks.Count = 1 Then Target.Select
With Selection.Font
.Color = -16776961
.TintAndShade = 0
End With


End Sub


but instead of pasting 100+ worksheets in the workbook, where should I place
this code?



--
Steve


Steve

VBA Event
 
Mike,

Thank you so much, it works perfect!
--
Steve


"Mike H" wrote:

Steve,

The workbook-sheet change applies to all sheets.

Alt+F11 to open VB editor. Double click 'This workbook' and paste this in on
the right

Note I've commented out .tintshade because that doesn't work in 2003 in fact
i'm only assuming it works in another version, I've never heard of it

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Hyperlinks.Count = 1 Then Target.Select
With Selection.Font
.Color = -16776961
'.TintAndShade = 0
End With
End Sub

Mike

"Steve" wrote:

In my entire workbook, I want to be able to change of the font of a cell when
the cell has a hyperlink in it.
This VB works if you paste it in each worksheet:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Hyperlinks.Count = 1 Then Target.Select
With Selection.Font
.Color = -16776961
.TintAndShade = 0
End With


End Sub


but instead of pasting 100+ worksheets in the workbook, where should I place
this code?



--
Steve



All times are GMT +1. The time now is 01:58 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com