wsnyder
Board Regular
- Joined
- Sep 23, 2018
- Messages
- 224
- Office Version
- 365
- Platform
- Windows
Hi all,
I am trying to apply a Hyperlink Cell Style to a Range (single cell in this case) but I keep receiving an error message:
Not sure what I'm doing wrong, seem correct and the style definitely exists in the workbook
Thoughts?
Thanks,
-w
I wrote a quick test in a new workbook in a new module and it works as expected so I'm not sure why my code in my other workbook does not work?
Test:
I am trying to apply a Hyperlink Cell Style to a Range (single cell in this case) but I keep receiving an error message:
Run-time error '450': Wrong number of arguments or invalid property assignment
Not sure what I'm doing wrong, seem correct and the style definitely exists in the workbook
Thoughts?
Thanks,
-w
VBA Code:
'Objects
dim myrangeobject as range
'Sheet protection
'If the worksheet is protected, unprotect it, else do nothing
bProtectionStatus = GetProtectionStatus(ws:=ws)
If bProtectionStatus Then
ws.Unprotect Password:="stuff"
End If
'Create range
With ws
Set myrangeobject = .Range(.Cells(8, 15), .Cells(8, 15))
End with
'Unlock cells
myrangeobject .Locked = False
'Test range
Debug.Print myrangeobject .Address <<-- This returns the correct address
'Apply cell styles
myrangeobject.style = "Hyperlink"
I wrote a quick test in a new workbook in a new module and it works as expected so I'm not sure why my code in my other workbook does not work?
Test:
Code:
Option Explicit
Sub foo()
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range
Set wb = ThisWorkbook
Set ws = wb.Worksheets(1)
Set rng = ws.Range("A1")
rng.Style = "Hyperlink"
Set rng = Nothing
Set ws = Nothing
Set wb = Nothing
End Sub