Note in another workbook cell

Olbap

New Member
Joined
Nov 6, 2009
Messages
19
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
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Have you activated the NwFile workbook? I think you need to do that first, based on your code.
 
Upvote 0
Thanks for answering, yes even if I activate the workbook I keep getting the same message...
 
Upvote 0
OK, I have run your code (as edited below):~

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   - edited out, incorrectly spelled variable name
Dim CurrentCell As String
'Dim CurrenSheet As String  - edited out, incorrectly spelled variable name
Dim CurrentSheet As String

CurrentCell = ActiveCell.Address
CurrentSheet = ActiveSheet.Name
NwFile = Workbooks("MyFile.xls").Worksheets("Sheet1").Range("NewFile").Value
Workbooks(NwFile).Sheets(CurrentSheet).Activate '- new line added
Workbooks(NwFile).Worksheets(CurrentSheet).Range(CurrentCell).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
'.TintAndShade = 0          - this didn't work, so I have commented it out
'.PatternTintAndShade = 0   - this didn't work, so I have commented it out
End With
Selection.AddComment
Selection.Comment.Visible = False
Selection.Comment.Text Text:=""
'Selection.Select
End Sub

Please note my comments.

It requires that the file with the name held in the range named "NewFile" is already open and has a named worksheet as defined in CurrentSheet. If so, it worked fine.
 
Upvote 0
You don't need to Select:

Code:
With Workbooks(NwFile).Worksheets(CurrentSheet).Range(CurrentCell)
    With .Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    .AddComment
    .Comment.Visible = False
    .Comment.Text Text:=""
End With
 
Upvote 0
Just another question, how could I fill the comment in the new file with text from the original cell? I tried recording that action with no result.
Thanks
 
Upvote 0
Create a string from the data that you want and change this:~

.Comment.Text Text:=""

Place your string after the = sign.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top