Is it possible to select shapes in Visio by specifying the coordinates of a selection rectangle? If so, how does one do this?
I need to select and delete any shape in a specific location on a Visio page.
I would like to be able to specify the coordinates of a lower left corner and an upper right corner on the page and have vba tell me the id's or handles or something that would allow me to delete these shapes as I need to place a new shape in that particular location. I am looking for something like
shapes = MyVisioPage.SelectByRectangularCrossingBox(lowerleftX,lowerleftY,upperrightX,upperrightY)
You could actually draw a rectangle with those coordinates and then use Shape.SpatialNeighbors to find out all shapes in that rectangle.. Something like this (VBA):
Function SelectByRectangularCrossingBox(page, _
lowerleftX, lowerleftY, upperrightX, upperrightY) As Selection
scopeId = page.Application.BeginUndoScope("try")
Set rc = page.DrawRectangle(lowerleftX, lowerleftY, upperrightX, upperrightY)
Set SelectByRectangularCrossingBox = rc.SpatialNeighbors(visSpatialContain, 0.01, 0)
page.Application.EndUndoScope scopId, False
End Function
The code is wrapped around with BeginUndoScope/EndUndoScope to cancel changes.
Related
i want to create HybridshapeProject from the given 2D points of a sketch
the project is creating like this refer below image
as you can see in the image the projects direction is created based on XYZ components of the selected vertex from the sketch
i have to get the components with VBA Code that i dont know
any help how to create HYbridshapeproject like this
the XYZ values in Direction Window those i need to get from selecting the axis system and the sketch which is present in the axis system
In order to use components as direction in a projection, you have to set the property .normal to false and assign a value to the .direction property.
In the following example, I assume that the HybridShapeFactory (HSF) and the inputs for the projection (refProjectedElement, refProjectionSupport) has been declared:
Dim ProjectFeature As HybridShapeProject
Set ProjectFeature = HSF.AddNewProject(refProjectedElement, refProjectionSupport)
ProjectFeature.Normal = False
Dim ProjectionDirection As HybridShapeDirection
Set ProjectionDirection = HSF.AddNewDirectionByCoord(0#, 0.95, 0.05)
ProjectFeature.Direction = ProjectionDirection
The macro recorder should be able to deliver code for the projection along components.
I have a slide that we use in my department to provide an overview of the progress regarding project document deliverables. It is shown in a graphic manner, and therefore a simple table view or similar cannot be used. Each of the document deliverables mentioned on the slide can have 3 different legends (figures), a square, triangle and arrow. These are color coded according to stakeholder responsibility of the deliverable. Right now we are changing each one of them manually during the project
What I am looking for:
Is there a VBA code that can easily be used to replace these figures according to project status?
I imagine each Project deliverable needs to be tagged with a position on the slide, and then a userform can be used to select which type of figure there should be assigned?
Anyone who can help me or point me in a direction to something that might help me is highly appreciated!
Thank you
Peter
Here's one approach in rough outline ...
Instead of individual shapes, use a square, triangle and arrow grouped. The user selects the group they want to work with then launches your dialog box where they choose the project status for that item. Your dialog box assigns a value from 1 to 3 to the status then calls SetVisibility like so:
Sub MakeItSo()
Call SetVisibility(2)
End Sub
SetVisibility first makes all of the shapes in the group invisible, then sets the appropriate shape to be visible:
Sub SetVisibility(lStatus As Long)
Dim x As Long
With ActiveWindow.Selection.ShapeRange(1)
For x = 1 To .GroupItems.Count
.GroupItems(x).Visible = False
Next
.GroupItems(lStatus).Visible = True
End With
End Sub
I've written some VBA code that automatically creates a chart. One of the axes on this chart doesn't use normal labels but a graphic. I've stored the graphic as an image and I use the .Copy and .Paste methods to get a copy of this image onto the chart.
Here is where it gets confusing. I need to rotate the image to get it aligned with the axis (using the .rotation property). But when I set the .top and .left properties the shape doesn't end up where I would expect. In fact setting the properties to 0 and 0 doesn't do what I would expect either. I've tried changing the order of the way I set the properties on the image object but it only appears in a different (wrong) location.
I'm sure I'm missing some vital aspect of how VBA/Excel is placing the object relative to what I'm setting the top and left properties to. Basically my goal is to make the image on the left side of the chart with the same width as the plot area's height (since the image is rotated I theorize this will make it the same size).
This code does not work:
Sheets(ImageSheet).Shapes("agreement").Copy
c.Chart.Paste
c.Chart.Shapes(1).Rotation=270
c.Chart.Shapes(1).width = c.Chart.PlotArea.height
c.Chart.shapes(1).left = 5
c.Chart.Shapes(1).top = c.Chart.PlotArea.top
I've also tried this code
c.chart.Shapes(1).top = c.chart.PlotArea.top + c.Chart.PlotArea.height
because I thought maybe it was calculating the "top" as the upper-left corner of the image object when it is not rotated (rotating 270 degrees makes this point in a place where it should align with the bottom of the plot area). But that doesn't do what I expected either.
The image is a skinny rectangle that acts as a label for the axis. The chart will end up being laid out like this: http://imgur.com/NrSXR and the axis label image would be something like this http://imgur.com/08EWU
What am I missing here?
Is it possible for you to align your chart into a position where the shape could rest align/on a cell?
IF YES then here is a suggestion:-
You could position shape into a cell. Then adjust the size to what you need. And rotate.
Then change its bring forward property be shown on the Chart.
Next Group Chart and the Shape
PS: I recorded a macro. However it's best if you could show us what your the exact picture (=how your sheeet/chart/image should look like) of your question.
I ended up rotating and resizing the image before copying and pasting to the chart and then positioning it. I had to use the IncrementLeft and IncrementTop methods rather than setting the left and top properties directly because that did not have the desired effect.
When doing the paste into the chart the object always ended up in the upper left hand-corner so I could increment to the left by the small amount I wanted as a margin I wanted there and increment the top by the value of PlotArea.top to align it with the plot area.
I was also surprised that when creating the copy of my image it retained the "name" i referred to it as when I copied it to the new sheet and chart. This was especially useful for positioning the image once it was on the chart.
I also needed execute this code at the very end of my procedure, after everything else had been positioned and aligned, or when I positioned the data labels for one of my series they wouldn't appear correctly.
Here is the code that I ended up using:
'make a copy of the label image and refer to it with a variable for convenience
Sheets(ImageSheet).Shapes("maturity").Copy
i = Sheets(ImageSheet).Shapes.Count
Sheets(ImageSheet).Paste
Dim axisImage As Shape
Set axisImage = Sheets(ImageSheet).Shapes(i + 1)
'rotate and resize the image
With axisImage
.Rotation = 270
.width = c.Chart.PlotArea.height
End With
'cut and paste the new image to the chart
axisImage.Cut
c.Chart.Paste
'position it in the chart using IncrementTop and IncrementLeft because setting the properties directly does not have the desired effect
c.Chart.Shapes("maturity").IncrementTop c.Chart.PlotArea.top
c.Chart.Shapes("maturity").IncrementLeft c.Chart.PlotArea.left - c.Chart.Shapes("maturity").height
I am creating a PPT Add-In and I am struggling to find the answer whether it is possible to determine the SlideRange position on a screen.
I would like to have a userform to be opened in a particular position (for example left = 10, top = 10 starting from left-top corner of the SlideRange). Unfortunatelly its position is based on a screen resolution. As the resolution can be changed and the PPT view type may be modified I am unable to establish the accurate position of SlideRange.
Is it possible to do with VBA?
Thanks in advance!
MJ
SlideRange has no particular position ... it's a collection of slides, and it's unclear what units you're using when you want to position the form at 10,10. But in normal full screen view, you can get the slide show window coordinates in points like so:
With SlideShowWindows(1)
Debug.Print .Left
Debug.Print .Top
Debug.Print .Height
Debug.Print .Width
End With
To get the results in screen pixels you have to use a Win API call to get the screen DPI (dots per inch).
Inches = Points / 72
Pixels = Inches * DPI
<< Do you know if it is possible to catch mouse events in PPT?
Only if the mouseclick changes the selection, and as you know, that's NOT all the time.
There's probably some way of doing it via the Win API but nothing like this is built into PPT itself.
I am trying to write a macro in VBA (Excel) that is assigned to a Checkbox. Whenever the checkbox is clicked, an "autoshape" will change its "order" from "Send to Back" to "Send to Front".
Basically, I am trying to create a dashboard with multiple panels, so that users can access information without moving between sheets. Each panel will have a rectangular autoshape as its background and the components of the panel will be "grouped" within the autoshape.
Can this be done? I would greatly appreciate any ideas into writing the code.
Thanks,
I'm not quite following your larger goal, but in order to bring a shape to the front use this:
If MyCheckBox.Value = True Then
MySheetName.Shapes("MyShapeName").ZOrder msoBringToFront
End If
You should select your desired ZOrder movement from the MsoZOrderCmd enumeration and your code should be in the Change event routine for your checkbox control.
EDIT:
You could also refer to the shape by its index number. For example:
MySheetName.Shapes(0).ZOrder msoBringToFront
Also, to get the name of a shape, either click it and look in the Name Box in the upper left corner of Excel (below the toolbars), or iterate through all the shapes like so:
Sub Macro1()
Dim MyShape As Shape
For Each MyShape In Sheet1.Shapes
Debug.Print MyShape.Name
Next MyShape
End Sub