Find out if PowerPoint Smart Guides are active - vba

PowerPoint 2010 introduces so called Smart Guides as described here. You can choose to enable or disable this feature in the Grid and Guides settings dialog with the check box "Display smart guides when shapes are aligned".
I'd like to query the setting by code and have looked through the object model for a corresponding property but didn't find any. So have I overlooked it or is it not exposed?

I think you would need to query the registry
HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\PowerPoint\Options\ShowSmartGuides
1 = on 0 =Off

We can Show and Hide custom Guides, I am using this in my application.
PowerPoint.Slide _pptSlide = null;
int SlideIndex = PowerPoint.Application.ActiveWindow.Selection.SlideRange.SlideIndex;
_pptSlide = PowerPoint.Application.ActivePresentation.Slides[SlideIndex];
_pptSlide.Application.DisplayGuides = Microsoft.Office.Core.MsoTriState.msoFalse;

Related

PowerPoint VBA add shape event/ add shape with tag value

i'am currently trying to add a small function to PowerPoint using VBA, my goal is to create a gadget that works kind of like Photoshop graphics layer.
My plan is to add a layer name Tag on each shape that is drawn by user, so later I can parse through every item by loop and preform lock/unlock, show/hide shapes based on it's tag value, such as:
Sub add_shape_with_layer_tag()
Set islide = ActivePresentation.Slides(1)
Set ishape = islide.Shapes.AddShape(msoShapeRectangle, 5, 5, 80, 60)
ishape.Tags.Add "Layer", "1"
End Sub
Sub show_hide_layer_one_shapes()
Dim active_slide As Slide
Set active_slide = ActiveWindow.View.Slide
For Each ishape In active_slide.Shapes
If ishape.Tags("Layer") = "1" Then
ishape.Visible = Not (ishape.Visible)
End If
Next ishape
End Sub
However, I couldn't found a way to achieve this, so I would like to ask whether there's a method that provides following functions?
override add shape function so I can sneak tag value in to shape every time user drawn a shape
catch add shape event (if this thing did exist) so i can add tag to the last added item
a way to set a default tag value to shape, just like setting default shape color/line width
or is there any better options that is also viable?
thanks.
20200728
To John, thanks for the advice, I did found some interesting event that might be helpful for some of my other projects, however I couldn't found events that able to trigger after custom function while shape is added.
To Steve, my plan is to add a modeless userform with list UI that manage layers, the shape tag and shape fill texture/color will be determined based on what list item that currently selected.
As to saving settings, I'll use VBComponents.CodeModule to dump existing settings in userforms to a VBA module and store as text, so in theory I should able to make this function self contained in one file.
Not totally an answer, sorry SO, but comments don't allow enough scope for this. So ...
To Steve, my plan is to add a modeless userform with list UI that manage layers, the shape tag and shape fill texture/color will be determined based on what list item that currently selected.
Ah, so you're creating your own "pseudo-layers". That wasn't clear. Thanks for the add'l info. As it happens, I have a selection manager add-in that works very similarly to what you're proposing.
To John, thanks for the advice, I did found some interesting event that might be helpful for some of my other projects, however I couldn't found events that able to trigger after custom function while shape is added.
The SelectionChange event should get you there. When it fires, you'll need to check first to see if the current selection is a shape or something else. If a shape, check to see if its .Index = current slide's .Shapes.Count and also to see if you've already tagged it. If no tag AND if it's the correct index, it'll be a newly added shape. If you're tagging ALL shapes, you may only need to check to see if the .Tag(name) is blank.
As to saving settings, I'll use VBComponents.CodeModule to dump existing settings in userforms to a VBA module and store as text, so in theory I should able to make this function self contained in one file.
Why not save any needed slide or presentation level info as further slide- or presentation-level tags? PPT can absorb quite a lot of info as tags w/o getting cranky.

VBA ungroup Shape (SmartArt)

Does anyone know how to ungroup SmartArt element via VBA?
Sub UngroupSmartArt()
Dim shapeWithSmartArt As Shape
Set shapeWithSmartArt = ActivePresentation.Slides(2).Shapes(2)
shapeWithSmartArt.Ungroup
End Sub
I get an error for this code:
"This member can only be accessed for a group."
It doesn't make any sense to me, because it's easily possible to do it in powerpoint itself (Right click on SmartArt -> Group -> Ungroup). It's driving me nuts :)
Can anyone help me with ungrouping SmartArt element/shape?
I also took a look on similar question, but it doesn't work properly, because ungrouped result is different in comparison to the one made via powerpoint itself.
Please help me out. I would really appreciate any help!
It is simply impossible to do it via VB code. That is also statement from Microsoft. Disadvantage of using SmartArt is also that user cannot record any actions with macro (using Excel) which are performed on this type of object/element.
It is also impossible to change width or height property of SmartArt nodes via VB, this was actually the reason why I wanted to change SmartArt element to shapes, because you can easily change width and height property of the shape via code.
Microsoft and their developers should really consider to make SmarArt element more developer-friendly, because I noticed I'm not the only one with these issues.
EDIT: Solution found! There is a way to execute commands from the powerpoint ribbon. You need to select your shape first, afterwards execute CommandBars.ExecuteMso with the action: SmartArtConvertToShapes.
Sub UngroupSmartArt()
Dim shapeWithSmartArt As Shape
Set shapeWithSmartArt = ActivePresentation.Slides(2).Shapes(2)
shapeWithSmartArt.Select
CommandBars.ExecuteMso("SmartArtConvertToShapes")
End Sub
This still doesn't change the fact and my point of view: Microsoft should really consider to make SmartArt element more friendly to developers!

VB.NET - How to view object properties via mouse hover inside a 'With' block during debugging

Working with VB.NET in Visual Studio 2015. During debugging, is there any way to view the value of a variable inside a 'With' block by hovering with the mouse?
For example, in the code below, if I hover over lSection or lSection.MomentZ or lSection.MomentY or others, VS displays information about the object and/or the value of the variable (as expected).
However, if I hover over any object starting with a period (.SectionIndex or .SectionLocation or .Mx or .M_y or .Vx), VS will NOT show any tooltip at all.
NOTE: I am aware that I can add the the variable to a Watch window. I know there are other ways to get the value of the variable, but I want to be able to just hover with the mouse because it is literally (yes, literally) 900 million times faster.
I could only find one other question similar to this one, but the answer does not explain whether or not there is ANY possible way to enable this feature (VS setting, registry hack, 3rd party add-on, i don't care how)
How to view VB.NET object properties in the debugger within a "With object" block?
With mCSIDetails
.ClearCSIResults()
' Section Index and Location
.SectionIndex = lSection.ID
.SectionLocation = Round(lSection.FracLen * mMember.Length, 3)
' Section forces and moments
.P = lSection.AxialForce
If liAxis = MemberOrientation.Strong Then
.Mx = lSection.MomentZ
.M_y = lSection.MomentY
.Vx = lSection.ShearForce_CSI_12
.Vy = lSection.ShearForceZ_CSI_12
ElseIf liAxis = MemberOrientation.Weak Then
.Mx = lSection.MomentY
.M_y = lSection.MomentZ
.Vx = lSection.ShearForceZ_CSI_12
.Vy = lSection.ShearForce_CSI_12
End If
End With
I posted the same question on the Visual Studio forum and the moderator was able to replicate the issue.
Apparently this is just the new (terrible) way the debugger works. So if you want to be able to mouse-hover and get a tooltip with the object/variable value, then don't use WITH blocks...

PowerPoint Add-on's weird behavior

I'm developing a PowerPoint2007 Add-on using VSTO(Visual Studio Tools for Office)
I'm trying to add a wavfile to slide and modify animation setting of the wave file.
The problem is occurred when I modify AnimationSettings.PlaySettings's member attributes of the wave file shape then some of animation effect in the slide deleted.
This behavior is very weird.
I don't understand why some of animation effect has been deleted after I modify the PlaySettings's member attributes.
code :
Shape s = Globals.ThisAddIn.Application.ActivePresentation.Slides[slideIndex].Shapes.AddMediaObject(wavFilePath, 0f, 0f);
s.Left = DEFAULT_LEFT_POS;
// If the below code run, some of animation effect are deleted.
s.AnimationSettings.Animate = Microsoft.Office.Core.MsoTriState.msoTrue;
s.AnimationSettings.AdvanceMode = PpAdvanceMode.ppAdvanceOnTime;
s.AnimationSettings.AnimationOrder = 0;
s.AnimationSettings.PlaySettings.PauseAnimation = Microsoft.Office.Core.MsoTriState.msoFalse;
s.AnimationSettings.PlaySettings.PlayOnEntry = Microsoft.Office.Core.MsoTriState.msoTrue;
Can anyone help me?
According to my experiences using AnimationSettings delete all 'exit effects' of other shapes. What you could possibly try is to explore the following PowerPoint objects/references:
`(slide).TimeLine.MainSequence`
which allows to change the animation order (you could add sound shape and than move it up before any exit effect start).
Check also if (Shape).SoundEffect object is not a good substitution for your needs.
I also change tag of your question into powerpoint-vba as it has a reference to that area too.

Add Icon to context Menu in VB.NET inside a windows forms appliction

I have searched many times here and on Google looking for a solution that did not envolve utilizing someone's class.
This context menu is pops up where the user right clicks inside a dataGridView
When adding the items the VB code is
Dim m As New ContextMenu()
m.MenuItems.Add(New MenuItem("Disassociate *A* Device"))
m.MenuItems.Add(New MenuItem("Purge Device Assosciations"))
Is there no simple way to reference a resource to add an icon to said menuItems?
Pseudo
m.MenuItem(0).Icon.Source = ....
?
Assuming that this is for a Windows Forms application.
Why not use the ContextMenuStrip?
Example:
Dim m As New ContextMenuStrip()
Dim item As New ToolStripMenuItem("Click Me!")
item.Image = My.Resources.image
m.Items.Add(item)
DataGridView1.ContextMenuStrip = m
You will need to set Owner Draw to true and actually draw the menu item yourself
Here is a good detailed example
I use the image propery and assign a system.drawing.image object to it.
You wont be able to do it in one line, you do the add once all the properties of the newmenu is set.