Messaging from Excel...

paddymack

Board Regular
Joined
Oct 24, 2002
Messages
143
Hi again, not sure if this is possible but I was wondering if a macro could be written to send a netsend message to a particular PC on the network when a certain sheet is accessed? any thoughts (running NT)
 
Sorry don't understand what your saying. From an MSDOS prompt the command "net send (userid) message here..." sends a pop up box to that userid's screen. This is what I'm trying to achieve from a macro.
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Building on Raider's post and my suggestion to use the Shell function, this code will send a message to the current user when the workbook is opened.

Code:
Option Explicit

Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, _
Nsize As Long) As Long

Private Sub Workbook_Open()
    Dim Buffer As String * 100
    Dim BuffLen As Long
    Dim FName As String
    Dim FNo As Integer
    Dim Txt As String
    Dim x
    BuffLen = 100
    FName = ThisWorkbook.Path & Application.PathSeparator & "NetSend.BAT"
    FNo = FreeFile
    GetUserName Buffer, BuffLen
    Txt = "NET SEND " & Left(Buffer, BuffLen - 1) & " Hello"
    Open FName For Output As #FNo
    Print #FNo, Txt
    Close #FNo
    x = Shell(FName, 1)
End Sub
 
Upvote 0
Brilliant! I'm really impressed. Not entirely sure what you've done here but It works exactly as I asked for - well done. Would it be possible to ask for a bit of an explanation of whats going on here so I can modify it further for my own needs? Tanks in advance.
 
Upvote 0
Well this bit uses a Windows API call to get the Username:

Code:
Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, _
Nsize As Long) As Long

Dim Buffer As String * 100
Dim BuffLen As Long
BuffLen = 100
GetUserName Buffer, BuffLen

at which stage the user name is in the variable Buffer with a length of BuffLen.

This bit sets up some variables, opens a batch file and writes a line of text to it:

Code:
'** NAME OF BATCH FILE **
FName = ThisWorkbook.Path & Application.PathSeparator & "NetSend.BAT"
'** NUMBER OF NEXT FREE FILE **
FNo = FreeFile
'** TEXT TO WRITE TO BATCH FILE **
Txt = "NET SEND " & Left(Buffer, BuffLen - 1) & " Hello"
'** OPEN THE BATCH FILE **
Open FName For Output As #FNo
'** WRITE THE NET SEND TEXT TO IT **
Print #FNo, Txt
'** CLOSE THE BATCH FILE **
Close #FNo

And this executes the batch file ie it types the line of text at the Command prompt:

Code:
x = Shell(FName, 1)
 
Upvote 0
There is an API that directly provides programmatic access to the NET SEND utility:

http://internettrash.com/users/fdb/broadcas.htm


========== Quote ===
Now, it's a little-known fact, but you can actually access this message sending functionality through the API. And we have all the code you need right here, ready for you to copy-and-paste, allowing you to instantly creating your own mini messenger or office news broadcast system!

To use, call BroadcastMessage, passing in three arguments - a user or machine name, a sender name, plus your actual message. The function will return a True or False dependant on success.

Sample Usage<pre>
x = BroadcastMessage("PYTHON", "Karl", "Boooo! It's me. Time for tea?")</pre>
=============== UNQUOTE ===========
This message was edited by Swamp Thing on 2002-11-12 03:18
 
Upvote 0
Here's a shot in the dark.

Everyone would have a linked workbook. Have a macro in each workbook that updates the links every 30 seconds. You can then have a Selection_Change event that would pop up a MsgBox with data in a cell with new information. Does this give you an idea?
 
Upvote 0
Ok I know I'm being greedy. Got Andrews code to work great.... but having seen Swamp Things code I'd really like to add a report to this so that I can see if the message delivery was successful or not. But I'm having difficulty in marrying the two codes together, anyone have any advice?
 
Upvote 0

Forum statistics

Threads
1,215,647
Messages
6,126,005
Members
449,279
Latest member
Faraz5023

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