Microsoft KB Archive/261943

= How To Use Basic Visio Operations from Visual FoxPro =

Article ID: 261943

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q261943



SUMMARY
As with the other Microsoft Office products, Microsoft Visio 2000 can be controlled through Automation from Visual FoxPro. This article demonstrates some basic functionality.



MORE INFORMATION
loVisio = CREATEOBJECT(&quot;Visio.Application&quot;) loDoc = loVisio.Documents.Add(&quot;&quot;) && No default template loPage = loVisio.ActivePage

loShape = loPage.DrawRectangle(1, 5, 5, 1)
 * !* The origin of a Visio drawing is the lower-left corner, not
 * !* the top left. However, the coordinates for DrawRectangle go
 * !* from top left to bottom right.

loShape.Copy   && Copy shape to the Clipboard loPage.Paste   && Paste copy into drawing page loShape.Cut    && Remove original

loShape = loPage.Shapes.Item(loPage.Shapes.Count)
 * !* Since the copied shape was the last one drawn, it can be retrieved
 * !* from the end of the shape collection.

loShape.Cells(&quot;PinX&quot;).Formula = &quot;Width * 0.5&quot; loShape.Cells(&quot;PinY&quot;).Formula = &quot;Height * 0.5&quot; loShape.Text = &quot;Switch back to VFP to close.&quot;
 * !* Move to the bottom left corner of the page by setting its
 * !* PinX and PinY formulas. PinX and PinY are the coordinates
 * !* that &quot;pin&quot; the shape to the page, so moving them moves
 * !* the shape. The pin for a rectangle is in the center, so
 * !* setting the coordinates as below puts the shape right on
 * !* the edges.

=MESSAGEBOX(&quot;Hit OK when you are ready to close the document.&quot;)

IF TYPE(&quot;loDoc&quot;) = &quot;O&quot; and ISNULL(loDoc) RETURN ELSE loDoc.Saved = .T. && Make Visio think the doc has already been saved loVisio.Quit     && so you can quit without a Save dialog. ENDIF

