Enter Comment by Code

mutrus

Board Regular
Joined
Sep 10, 2002
Messages
80
When a comment is added to a cell it contains the users login by default.

I wish to add comments by using code. How can I assign the users login to a variable
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
> I wish to add comments by using code.

Range("A1").AddComment "Juan Pablo"

> How can I assign the users login to a variable

MyVar = Application.UserName
 

Ivan F Moala

MrExcel MVP
Joined
Feb 10, 2002
Messages
4,209
On 2002-09-11 20:54, mutrus wrote:
When a comment is added to a cell it contains the users login by default.

I wish to add comments by using code. How can I assign the users login to a variable
Actually it doesn't add the users login name.
It meely uses the User name from the Options droplist in Excel, which anyone can change.

If you want the login user name then thius may help;

<pre/>
Declare Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" ( _
ByVal lpName As String, _
ByVal lpUserName As String, _
lpnLength As Long) As Long

Function GetName() As String
Dim strUserName As String
strUserName = Space(255)
WNetGetUser "", strUserName, 255
GetName = Trim(strUserName)
End Function
</pre>
 

mutrus

Board Regular
Joined
Sep 10, 2002
Messages
80
Juan Pable G - thanks that works

Ivan F Foala - your reply does more than I asked but has now prompted me to think about that approach

Both replies thanks
 

mutrus

Board Regular
Joined
Sep 10, 2002
Messages
80

ADVERTISEMENT

Ivan - I just realised what your logo was. No wonder I got a fast reply to my post.

Cheers from a fellow Kiwi

Go the Warriors
 

Ivan F Moala

MrExcel MVP
Joined
Feb 10, 2002
Messages
4,209
On 2002-09-12 01:31, mutrus wrote:
Ivan - I just realised what your logo was. No wonder I got a fast reply to my post.

Cheers from a fellow Kiwi

Go the Warriors

Go the Warriors !
Your IP is the same as fellow Mrexcel MVP Paddy
Where are you ? Wellington ?
 

Forum statistics

Threads
1,144,119
Messages
5,722,592
Members
422,447
Latest member
knopp

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
Top