multiple monitors

  • Thread starter Thread starter Robert Flanagan
  • Start date Start date
The practical answer is no. However, threre is spyware, malware or whatever
you want to call it that has been developed that could possibly allow a
hacker or even someone authorized access to determine a system's
configuration. But I do not know of a way to do it with VBA.
 
I'm pretty sure this will work. Put the following marked code in a Module
(Insert/Module from the VB editor's menu bar)...

'****************** Start Of Code ******************
Private Declare Function EnumDisplayMonitors Lib "user32.dll" _
(ByVal hdc As Long, ByRef lprcClip As Any, _
ByVal lpfnEnum As Long, ByVal dwData As Long) As Long

Private MonitorCount As Long

Public Function NumberOfMonitors()
MonitorCount = 0
EnumDisplayMonitors ByVal 0&, ByVal 0&, AddressOf MonitorEnumProc, ByVal
0&
NumberOfMonitors = MonitorCount
End Function

Private Function MonitorEnumProc()
MonitorCount = MonitorCount + 1
MonitorEnumProc = 1
End Function
'****************** End Of Code ******************

And then simply call the NumberOfMonitors function from your own code. For
example...

Sub Test()
If NumberOfMonitors = 1 Then
MsgBox "There is only one monitor on this system."
Else
MsgBox "There are 2 or more monitors on this system"
End If
End Sub
 
Rick, thanks. I'll try it tomorrow (after I borrow the wife's monitor!).

If anyone has two monitors and can also test, please do so.

Bob
 
I see one of the statements word-wrapped. Here is the same code again, but
using a line continuation to make sure the statement doesn't word-wrap....

'****************** Start Of Code ******************
Private Declare Function EnumDisplayMonitors Lib "user32.dll" _
(ByVal hdc As Long, ByRef lprcClip As Any, _
ByVal lpfnEnum As Long, ByVal dwData As Long) As Long

Private MonitorCount As Long

Public Function NumberOfMonitors()
MonitorCount = 0
EnumDisplayMonitors ByVal 0&, ByVal 0&, AddressOf _
MonitorEnumProc, ByVal 0&
NumberOfMonitors = MonitorCount
End Function

Private Function MonitorEnumProc()
MonitorCount = MonitorCount + 1
MonitorEnumProc = 1
End Function
'****************** End Of Code ******************
 
I have two monitors and the function returns 2 for me. I don't have a single
monitor system to test it on (sorry, I don't want to disconnect one monitor
because of the way I have my Desktop icons set up); but if you have a single
monitor system, and if the function returns 1, then that should mean the
code works correctly.
 
If anyone has two monitors and can also test, please do so.

It works for me as expected with 4 monitors.


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
works perfect if just one monitor. I would add a second but then the wife
couldn't see me behind the desk. Hmm......

Thanks,

Bob
 
Rick, I got the impression that the OP was talking about remote access.
Your code appears to be for local access, or am I reading it wrong?
 
I just figured the OP was distributing his workbook to one or more people
and wanted to be able to check if these users had one or more monitor so he
could adjust the functionality of his code around either hardware situation.
 
Thanks for the confirmation. Just one thing though... YOU HAVE 4
MONITORS?!!?!

That's right, four 26" flat panels at 1920x1200, pumped by two NVidia
GeForce 1GB cards. It is like sitting in mission control.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
Wow! That is impressive. I have a 26" and a 19" and everything I need to do
fits on those two screens... I can't imagine trying to make use of 2 more
large screens.
 
Back
Top