Sinking events of a remote workbook

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,642
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I am not experienced with network programming so I am asking here if the following prank would work (this is just an illustrative example)

Ok- Let's say a remote workbook (located in a network shared Drive/Folder) is currently opened by some user on the network and I wanted to play a prank on them by undoing their worksheet data input as follows :

Code in my workbook module: (Obviously, C:\RemoteWb.xls would need to be modified to the server path)
Code:
Private WithEvents Xlapp As Application

Sub HookRemoteWorkbook()
    Set Xlapp = GetObject("C:\RemoteWb.xls").Application [COLOR=#008000]'change to server pathname[/COLOR]
End Sub

Private Sub Xlapp_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    With Sh.Application
        .EnableEvents = False
        .Undo
        Target = "Go to hell !!"
        .EnableEvents = True
    End With
End Sub

I tried the above code on a second excel instance on my computer and it worked as expected but would this also work if the shared network workbook was opened remotely by someone on the network ?

Another question: Is there a way of knowing if a workbook or application is currently being referenced by another program ?

Regards
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
No that wouldn't work - it would just attempt to open the file on your computer and connect to that application instance. Unfortunately, although CreateObject allows you to specify a server name, GetObject doesn't, so you can't hook into an instance running on another machine that way.
 
Upvote 0
Thanks for the info Rory

So maybe the way to go is to use CreateObject to open an invisible xl application instance on the remote computer , have this newly created instance open the hooking workbook and run the hooking code from its open event

Edit : Any thoughts on my second question ?
 
Upvote 0
That could work, in theory.

Re #2, I'm afraid I don't know. Nothing I'm aware of.
 
Upvote 0
Ok thank you .. If I anything interesting comes up, I'll post back
 
Upvote 0

Forum statistics

Threads
1,216,033
Messages
6,128,427
Members
449,450
Latest member
gunars

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