Hello,
I am trying to run this macro and I get always an "Error 1004" with the select instruction. The aim is to put a note on the same cell in the same sheet in a second (NewFile) workbook and highlight it. Could someone help me?
Thanks in advance,
Here is the code:
Sub FetchNoteinNewFileActivecell()
'
' This macro highlights in red the cell in the NewFile corresponding to the selected cell and adds an empty comment
' Warning: this works only if there is a sheet in the target (NewFile defined in range in Sheet1) file with the same name as the active sheet
'
Dim NwFile As String
Dim CurrenCell As String
Dim CurrenSheet As String
CurrentCell = ActiveCell.Address
CurrentSheet = ActiveSheet.Name
NwFile = Workbooks("MyFile.xls").Worksheets("Sheet1").Range("NewFile")
Workbooks(NwFile).Worksheets(CurrentSheet).Range(CurrentCell).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.AddComment
Selection.Comment.Visible = False
Selection.Comment.Text Text:=""
'Selection.Select
End Sub
I am trying to run this macro and I get always an "Error 1004" with the select instruction. The aim is to put a note on the same cell in the same sheet in a second (NewFile) workbook and highlight it. Could someone help me?
Thanks in advance,
Here is the code:
Sub FetchNoteinNewFileActivecell()
'
' This macro highlights in red the cell in the NewFile corresponding to the selected cell and adds an empty comment
' Warning: this works only if there is a sheet in the target (NewFile defined in range in Sheet1) file with the same name as the active sheet
'
Dim NwFile As String
Dim CurrenCell As String
Dim CurrenSheet As String
CurrentCell = ActiveCell.Address
CurrentSheet = ActiveSheet.Name
NwFile = Workbooks("MyFile.xls").Worksheets("Sheet1").Range("NewFile")
Workbooks(NwFile).Worksheets(CurrentSheet).Range(CurrentCell).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.AddComment
Selection.Comment.Visible = False
Selection.Comment.Text Text:=""
'Selection.Select
End Sub