Visio VBA : Connect a line shape to two other shapes - vba

I am dropping shapes on my Page via VBA UserForms. Amongst others I need to drop a "curved line" shape which should connect two specified shapes.
I found out how to directly create a connection here but I want the shape from my specific master because it has some custom Data Properties.
I expected there to be some Fields in the DataSheet of the Connector-Shape where I could reference the start and end shapes? could not find anything more helpful.
Thanks for any hints!

Solution from here
Dim shp As Visio.Shape 'connector
Dim src As Visio.Shape 'connect this
Dim aim As Visio.Shape 'to this
[...] 'Set shape variables
shp.Cells("BeginX").GlueTo src.Cells("PinX")
shp.Cells("EndX").GlueTo aim.Cells("PinX")

Related

How can I select all in Powerpoint VBA?

I have been struggling for a while to find a VBA code to select all the slides and all the shapes of a presentation (for some reason this seems to be of no one's interest). I have tried to set up a range with all the slides and then select all the shapes of the range, but that does not work. I also try looping slide by slide and accumulate the selection (msoFalse), but for that you also need to activate each slide and I was unable to do that.
I think selecting all the slides and shapes at once is useful to manipulate the fonts or run a full spell check. Your help would be really appreciated!!
Selecting objects in VBA is generally to be avoided. It's unreliable and slow. Instead, loop through every shape on every slide and perform whatever operation you need:
Sub DoStuffToShapes()
Dim oSlide as Slide
Dim oShape as Shape
For each oSlide in ActivePresentation.Slides
For each oShape in oSlide.Shapes
'Do stuff to the shape
Next oShape
Next oSlide
End Sub
If you've created a font theme and applied it to the Slide Master and Layouts, it's usually easier and faster to change fonts by modifying the theme and/or master rather than using VBA. VBA isn't needed for a spellcheck either.

Changing Shape Color in Visio

Need some help!
I'm relatively knowledgeable when it comes to macros, VBA, scripts, etc., but Visio coding is an all new monster to me.
In short, I have a warehouse map layout with simple square shapes marking product locations, and I want to color-code the squares based on their Prop._VisDM_F2 data element. My code so far seems to work, but only for the 1st shape in the group of squares, but sometimes the master shape consists of 1 square, sometimes 6, and everything in between.
I've learned that the # in "Shapes(#)" selects which square gets changed, but I want them ALL to change. I've tried to get a count of how many individual shapes are in each master shape to use a variable integer as the #, but it didn't work.
Surely such a simple task can't really this complicated so I'm probably just missing something a step. Any help would be greatly appreciated!
'''
Dim selectObj As Visio.Shape
For Each selectObj In ActiveWindow.Selection
If selectObj.CellExistsU("Prop._VisDM_F2", Visio.VisExistsFlags.visExistsAnywhere) Then
selectObj.Shapes(1).Cells("Fillforegnd").FormulaU = visWhite
End If
Next
End Sub
'''
Shapes can have sub-shapes which are accessed through the Shapes property as per your code (note that most Visio collections are 1 rather than 0 based).
You can address the sub-shapes collection either by index or with a further for each. So given that you may or may not know the depth of your sub-shapes you can recurse through them something like this:
Sub ApplyFillToAll()
Dim shp As Visio.Shape
For Each shp In ActiveWindow.Selection
If shp.CellExistsU("Prop._VisDM_F2", Visio.VisExistsFlags.visExistsAnywhere) Then
SetFill shp, "RGB(255,0,0)"
End If
Next
End Sub
Public Sub SetFill(ByRef shpIn As Visio.Shape, fillFormula As String)
Dim shp As Visio.Shape
For Each shp In shpIn.Shapes
shp.Cells("FillForegnd").FormulaU = fillFormula
SetFill shp, fillFormula
Next
End Sub
Note that the formula that you're setting is a string and so is wrapped in double quotes, and the above will set all of the sub-shapes to red with the SetFill method calling itself to navigate down through the tree.
I'll add a link to a very old post that you might also find useful:
https://visualsignals.typepad.co.uk/vislog/2007/11/looping-through.html

Is it possible to update only a selected linked object in PPT?

I'm trying to build a macro which will update only the selected linked object within a PowerPoint, but I cannot figure out how to do it.
The first part below is what I've used to update all linked objects, but I am currently dealing with massive Excel files, and presentations with 200+ linked objects, so one-at-a-time updating is the only way to go unfortunately.
The second part is what I was hoping would work.
First part:
Dim sld As Slide
Dim sh As Shape
For Each sld In ActivePresentation.Slides
For Each sh In sld.Shapes
If sh.Type = msoLinkedOLEObject Then
sh.LinkFormat.Update
End If
Next
Next
Second part:
With ActiveWindow.Selection
.LinkFormat.Update
EndWith
I'm pretty inexperienced with PPT VBA, so please bear with me. Is it possible to build something like this? (It's going to be part of a more complicated macro, so it ultimately will be more convenient than just Right Click + Update Link)
Give this a try:
Sub UpdateOLELink()
ActiveWindow.Selection.ShapeRange.LinkFormat.Update
End Sub

How to instantiate a Graph Chart?

I am currently trying to create a chart, e.g. a piechart through word vba.
The problem is that the machine(s) where this word vba will be run do not have excel available, only word and ms graph.
I have tried to create a chart with ms graph, but I am not able to make it work.
As from the code below, I can create charts with inlineshapes and chart and I get a nice bar chart presented in the word window.
I am not able to instantiate the chart element for Ms Graph. I found a french guide that shows how it should be done, but I am not able to get the "me.graphique1"-part to make sense.
Inlineshapes
Dim vlChart As Chart
Set vlChart = ActiveDocument.InlineShapes.AddChart2.Chart
Graph
Dim vlChart As Graph.Chart
Set vlChart = Me.Graphique1.Object.Application.Chart
I would expect to be able to create a graph object, but I don't know what I am doing.
No guarantees that this will still work, since MS Graph has long been deprecated. The following code sample demonstrates how to insert an MS Graph object and access its data sheet.
This code requires a reference to the MS Graph object library in VBA Tools/References. I highly recommend you use it, at least while writing the code so that you have Intellisense.
Dim grph as Graph.Chart
Dim grphData as Graph.DataSheet
Dim grphApp as Graph.Application
Dim doc as Word.Document
Dim oleF as Word.OLEFormat
Dim rng as Word.Range
Set doc = ActiveDocument
Set rng = doc.Content
Set oleF = doc.InlineShapes.AddOLEObject(ClassType:="MSGraph.Chart.8", Range:=rng).OLEFormat
oleF.DoVerb
Set grphChart = oleF.Object
Set grphApp = grphChart.Application
Set grphData = grphApp.DataSheet
grphData.Cells.Clear
'Now start entering the data and formatting the chart

VBA - Ungroup a Table in PowerPoint

I am looking for an automated way to ungroup a table in power point to create shapes.
I found the following tutorial:
Tutorial
Further, I wanted to record the macro(I am quite new to vba), however in power point 2010 the macro recorder is not available any more. Any suggestions, how to create the above tutorial in vba?
I appreciate your replies!
Here's an example to get you started. Be sure to select the table you want to work with first.
Sub PasteAndUngroup()
Dim oSh As Shape
Dim oSl As Slide
Set oSh = ActiveWindow.Selection.ShapeRange(1)
Set oSl = oSh.Parent
oSh.Copy
Set oSh = oSl.Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1)
oSh.Ungroup
End Sub