Solved

Automatically position the application window for Visio 2013

Posted on 2014-02-07
11
521 Views
Last Modified: 2014-02-12
I use Excel 2010 and Visio 2013.
Excel file (name: 'XL_driver') creates/ selects a type of Visio file (name: 'vis_slave'), via early binding, and xl vba procedures control all vis-slave vba procedures.

I wish the XL-diver application window to appear on screen above vis_slave application window, so the USER can conveniently use xl's ribbon buttons to work with vis_slave. Thus, when the USER drags xl_Driver about the screen, its vis_slave should follow.

First steps in xl_driver code show evidence of progress (#2), but ultimate failure (#3):

1. Application.top and Application.height give the correct top and height values for the xl_driver app window

2. Accessing the visio application object model from Excel:
  'early binding
    Set visioApp = New Visio.Application
  'VisioApp is legitimate: the following exits visio application
  If Not visioApp Is Nothing Then visioApp.Quit
  Set visioApp = Nothing

3. 'Now try to position visio app window below foot of xl app window
    Set visioApp.top = Application.top + Application.height << BUG

Bug: 'Object does not support this property or method.
Problem: I cant find a path through the object model from visio application to .top

How do I do this, please?

Kelvin4
0
Comment
Question by:Kelvin4
  • 6
  • 5
11 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,

After point 2 I do not see an "End If"
visioApp is already Nothing when your bug appear

EDIT Maybe

visioApp.ActiveWindow.Top

Open in new window


Visio.Application  has no Top Property

Regards
0
 

Author Comment

by:Kelvin4
Comment Utility
Rgonzo,
Thanks, my text was not quite clear.  To clarify:  #2 was an independent bit of evidence that 'visioApp' is a legitimate object in my code ( though I inadvertently omitted 'End If' from the copied snippet ).

I confirm that in my development code, visioApp was not preceded by  Set visioApp = Nothing. So visioApp had value, but '.Top' was incorrectly assigned as a property in:
Set visioApp.top = Application.top + Application.height

Unfortunately in your EDIT: 'Top' is not a child property of the 'ActiveWindow' object either.

Kelvin
0
 
LVL 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 80 total points
Comment Utility
Hi,

in Visio you have the WindowHandle32  property

Private Declare Function MoveWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Public Sub Example() 
 
Dim vsoWindow As Visio.Window 
Dim lngWindowHandle32 As Long 

Set vsoWindow = ActiveWindow 
 
lngWindowHandle32 = vsoWindow.WindowHandle32 
 
lDone = MoveWindow(ByVal lngWindowHandle32, ByVal 0, ByVal 0, ByVal 1920, ByVal 1200, ByVal 1)
If lDone = False Then MsgBox "Failed" 
End Sub 

Open in new window

not tested
EDIT

to find the Application window you could loop them in Application.Windows and test for

Window.Type = visApplication ' 5
 
Regards
0
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,


to find actual position pls try

Private Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As IntPtr, ByRef lpRect As RECT) As Integer


Private Structure RECT
    Public Left As Int32
    Public Top As Int32
    Public Right As Int32
    Public Bottom As Int32
End Structure


Dim visRect As RECT

lngWindowHandle32 = vsoWindow.WindowHandle32 
intResult = GetWindowRect(byVal lngWindowHandle32, visRect)

Open in new window

0
 

Author Comment

by:Kelvin4
Comment Utility
Thanks, .... digesting!
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:Kelvin4
Comment Utility
Hi, Rgonzo

I took up your text
<<<<      to find the Application window you could loop them in Application.Windows and test for Window.Type = visApplication ' 5     >>>>>

... and ran this sub  in a visio standard module:

Sub getDrawingWindow() ------------------------------------------------------------------
Dim win As Visio.Window

For Each win In Visio.Application.Windows
  Debug.Print "win.type = "; win.Type & "; win.subType = "; win.SubType & "; win.ID = "; win.ID
Next

'Debug.Print output was:  win.type = 1; win.subType = 128; win.ID =  8642

End Sub -------------------------------------------------------------------------------------------

win.type = 1 is the drawing window.
In this loop, I'm missing the Application window (win.type = 5)?

Can you advise, thanks
Kelvin
0
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,

Somewhere I saw

Application.WindowHandle32

Could that be the solution?
0
 

Accepted Solution

by:
Kelvin4 earned 0 total points
Comment Utility
Below, I copy some stuff where WindowHandle32 object is defined via the ActiveWindow object. My problem is to set the top level Application window as an object as the first step.
 
Lets see what other advice we get,
Regards
Kelvin

http://msdn.microsoft.com/en-us/library/office/ff768775.aspx:

Public Sub WindowHandle32_Example()
 
 Dim vsoWindow As Visio.Window
 Dim lngWindowHandle32 As Long
 
 'Get the active window.
 Set vsoWindow = ActiveWindow
 
 'Get the 32-bit handle of the active window.
 lngWindowHandle32 = vsoWindow.WindowHandle32
 
 'Verify that you got the handle.
 Debug.Print "The active window handle is"; lngWindowHandle32
 
End Sub
0
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,

pls try
Set visioApp = New Visio.Application 
lngWindowHandle32 =  visioApp.WindowHandle32 

Open in new window


Regards
0
 

Assisted Solution

by:Kelvin4
Kelvin4 earned 0 total points
Comment Utility
I'm afraid I do not know how to use your suggested start point (above).
I'm not certain it is so clear a start point, but if you can show it is, then I'd be delighted to pay you my points.

I believe a successful answer would provide a window object with window.type = 5.  
I do welcome a solution that demonstrates  that outcome.

thanks
0
 

Author Closing Comment

by:Kelvin4
Comment Utility
This a new part of the Visio object model to me

My question had a typo in it, and some clarification was needed.
The Expert gave me one important piece of information:
for the Application window: Window.Type = visApplication  , and value = 5.
I'd like to suggest that could be worth 80 points.

From the above advice, I then made some minor progress, but got no solution to the question that was clearly stated in the Title and subsequent text.

I now know that the Application Window object is accessed via:
Application.Window, for example:
Application.Window.Caption = "Visio Professional"

However, Application.Window is READ ONLY source: http://msdn.microsoft.com/en-us/library/office/ff769161.aspx
.. and so position properties like .top .left etc do not exist.

Thus a different method of positioning the visio application window is required (if it exists).

I now wish to close this question fairly and ask another to meet the original need.

I appreciate the Experts' interest and input, but I suggest this question beat us both?
I am open to comment.

Kelvin
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Toggle Visio  Layers On and Off 10 1,498
MS VISIO 2013 - features 3 100
Logical Diagram of network in Visio 5 60
Viso Text 4 41
Have you ever created a custom Visio stencil – a collection of your own unique master shapes – and then created a drawing by dragging masters onto the drawing page? Have you then made changes to the stencil master and wondered why the shapes on the …
The ability to add structure to Visio diagrams using containers, lists and callouts is one of my favorite features in Visio 2010. In this article I’ll describe a mashup of containers and lists that meet a real-world need. Prior to reading this ar…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now