Adding Section/Chapter label to slide header - powerpoint

I'm wondering if Powerpoint has a feature where I can automatically add a formatted header to each slide that displays the section and/or chapter. I'm presenting my thesis, and it is divided into sections, like "method" or "evaluation", and I would love it if I could automatically display that in the header of each slide. Preferrably, this would be automatically fetched from my powerpoint sections.
I want this look, which I'm currently producing manually for each slide.

Here's a bit of starter code to get you the name of the section each slide belongs to.
Over to you to provide the code to add the text to each slide and position/format it.
Sub Test()
Dim oSl As Slide
' Make sure there ARE sections
If ActivePresentation.SectionProperties.Count > 0 Then
For Each oSl In ActivePresentation.Slides
Debug.Print GetSection(oSl)
Next
End If
End Sub
Function GetSection(oSl As Slide) As String
' Returns the name of the section that this slide belongs to.
With oSl
Debug.Print .sectionIndex
GetSection = ActivePresentation.SectionProperties.Name(.sectionIndex)
End With

PowerPoint has no function like this built-in.
However, like most Office products, PowerPoint does have a very powerful VBA macro engine, which would certainly be capable of doing this.
Your macro would have to capture the Section name based on whatever parameters you choose to use to mark that, and then it could place that information anywhere you please within subsequent slides.
Because slides are more about visual layout than programmatic auto-creation, this is something you'd have to build yourself.

Related

How to replace text in Powerpoint with activeX textbox value?

I'm sorry if I can't explain this very well. Language barrier and all that. Might explain why I wasn't able to google a solution... Anyway.
I'm trying to make an interactive Powerpoint where in the first slide the user writes their name in an ActiveX textbox and the name then repeats in several other slides. Because the name would be in the middle of different texts my solution was to add a placeholder word that would then be replaced with the textbox value. I was able to Frankenstein a code that replaces one name with another that works well enough but I can't get the textbox to work with it. Best I can do is replace the placeholder name with some variation of TextBox1.Value and while I know what causes that issue I can't work out a solution.
Not sure if it makes a difference but the plan is to add some sort of "OK" button next to the active textbox that runs the macro.
Sub Findandreplace()
Dim sld As Slide
Set sld = ActivePresentation.Slides(1)
Dim shp As Shape
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "word1", "word2")
End If
End If
Next shp
Next sld
End Sub
ActiveX objects have a different set of properties/methods than regular PPT shapes. Assuming you have a reference to the AX textbox in a variable oSh,
osh.OLEFormat.Object.Text
will give you the text in the ActiveX textbox

How do I add a hyperlinks to image using VBA?

I have a script that will run on GPO on Windows Server 2012.
It's pretty simple stuff, but I cannot fathom how to add a hyperlink around an image! I have:
objSelection.InlineShapes.AddPicture "linktoimage.html"
This works a dream, I can see the image and there is no issue. But how do I add a hyperlink to this image so that when folks click on it they are taken to my desired hyperlink location. I know adding an image is simply a line of code, hoping for same for adding a hyperlink.
I am not doing this in excel or anything of the kind, just Notepad++
Assuming this is about Word, you need to save a reference the shape you just created and then use that reference as an argument to Document.Hyperlinks.Add
Option Explicit
Sub LinkImageTest()
Dim oSelection As Selection
Dim oDocument As Document
Dim oShape As InlineShape
Set oSelection = Application.Selection
Set oDocument = oSelection.Document
Set oShape = oSelection.InlineShapes.AddPicture("https://yt3.ggpht.com/-Pde_zs2tuj0/AAAAAAAAAAI/AAAAAAAAAAA/iBq9KSwTTLk/s88-c-k-no-mo-rj-c0xffffff/photo.jpg")
oDocument.Hyperlinks.Add oShape, "http://www.microsoft.com"
End Sub

adding a default note to powerpoint

I want to modify powerpoint so that the notes section always contains a static text. specifically I want to add
<tags></tags>
to the notes section of every slide created. I was hoping for an easy way to to do this on the master slide, but so far Dr. Google hasn't shown me how. I tried just adding it to the Notes Master but that didn't work.
I'm open to programmatic solutions, but would rather have a settings based solution if it exists.
How do I add text to every slide's note section upon slide creation?
"notes section" could mean different things. If you want some text to appear on every notes PAGE, where it'll appear on all printed notes, you just need to add it to the notes master.
If you want it to appear in the notes text that's part of every notes page (and also appears in the notes pane beneath the slide in Normal view), I don't think it's possible, at least not w/o having an installed add-in.
I have researched this a lot as well, but there doesn't seem to be any way of adding predefined text to the Notes area under the slide in the Slide Master.
You can do it with a macro after the presentation is created. Instead of using "[tag]" & "[/tag]", you can use something easier to type like "/1" and "\1", then use the macro to find and replace your "numbered" tags with the text equivalents.
Something like this:
Dim aSlide as Slide
Dim noteShp as Shape
For each aSlide in ActivePresentation.Slides
For Each noteShp In aSlide.NotesPage.Shapes
If noteShp.PlaceholderFormat.Type = ppPlaceholderBody Then
If noteShp.HasTextFrame Then
If noteShp.TextFrame.HasText Then
noteShp.TextFrame.TextRange.Text = Replace(noteShp.TextFrame.TextRange.Text, "/1", "<tag>")
noteShp.TextFrame.TextRange.Text = Replace(noteShp.TextFrame.TextRange.Text, "\1", "<\tag>")
End if
End If
End If
End If
Next
Next
I am doing exactly the same thing as you are.
I use html style tags in the notes section (the area underneath the slide in Normal View) to organize information and automatically create supporting documentation for the presentation.
Right now, I am doing it by manually by pasting the tags into the Note area under each slide, but if anyone knows how to pre-populate the Note area each time a new slide is added (by modifying the Slide Master settings - not the Notes Master), that would be fantastic.
Looking forward to see if anyone has a solution to this!

How to Save Embedded Images in Powerpoint 2013 To Local Disk Through VBA?

I have lot of pictures embedded in the Microsoft Powerpoint 2013 presentation. In Powerpoint 2013, I can right click on a picture object and then use "Save As Picture" to save the image to local disk. But this is manual way. I want to know if there is any way of automating the same through VBA? I am able to loop through the Shapes collection and then determine the type of the object. But I am not able to figure out which properties or methods are relevant for storing the picture to the local disk? Following is code snippet of iterating through the Shapes collection and determining if the Shape is of type msoPicture
For currentSlideIndex = 1 To totalSlidesCount
Set currentSlide = ActivePresentation.Slides(currentSlideIndex)
For Each mediaShape In currentSlide.Shapes
mediaCounter = mediaCounter + 1 'for each shape in the slide
If currentSlideIndex = 3 Then
If mediaShape.Type = msoPicture Then
MsgBox ("Shape Type Picture is " + CStr(mediaShape.Type) )
End If
End If
Next mediaShape
mediaCounter = 0 'Reset to 0 for the new slide
Next
You can export the current shape to a picture using the shape's .Export method.
This is normally hidden, so you won't get intellisense help on it by default, so:
Go into the IDE
Press F2 to open the object browser
Rightclick in the pane to the right of Classes, where you see "Members of ..." at the top.
Put a check next to Show Hidden Members
Now you'll get intellisense guidance when you type .Export on a slide shape.
Note also that if a shape is Type 14 (placeholder), it can contain a picture, so you may want to add something like:
If mediaShape.Type = msoPlaceholder Then
If mediaShape.PlaceholderFormat.ContainedType = msoPicture Then
' it's also a picture
End If
End if
And to add further entertainment value you might also have .Type = msoLinkedPicture, and even in some cases msoEmbeddedOLEObject that happens to be a picture.

How to copy to clipboard using Access/VBA?

Using VBA inside Access2003/2007.
How to copy the contents of a string variable to the clipboard?
This site recommends a creating a zero length TextBox, copying the string to the TextBox, then running DoCmd.RunCommand acCmdCopy. Ugh. I mean, we may go down the route. But still. Ugh.
While the MS knowledgebase article shows us how to do it but it involves a number of Windows API calls. Yuk.
Are those the only two options?
VB 6 provides a Clipboard object that makes all of this extremely simple and convenient, but unfortunately that's not available from VBA.
If it were me, I'd go the API route. There's no reason to be scared of calling native APIs; the language provides you with the ability to do that for a reason.
However, a simpler alternative is to use the DataObject class, which is part of the Forms library. I would only recommend going this route if you are already using functionality from the Forms library in your app. Adding a reference to this library only to use the clipboard seems a bit silly.
For example, to place some text on the clipboard, you could use the following code:
Dim clipboard As MSForms.DataObject
Set clipboard = New MSForms.DataObject
clipboard.SetText "A string value"
clipboard.PutInClipboard
Or, to copy text from the clipboard into a string variable:
Dim clipboard As MSForms.DataObject
Dim strContents As String
Set clipboard = New MSForms.DataObject
clipboard.GetFromClipboard
strContents = clipboard.GetText
User Leigh Webber on the social.msdn.microsoft.com site posted VBA code implementing an easy-to-use clipboard interface that uses the Windows API:
http://social.msdn.microsoft.com/Forums/en/worddev/thread/ee9e0d28-0f1e-467f-8d1d-1a86b2db2878
You can get Leigh Webber's source code here
If this link doesn't go through, search for "A clipboard object for VBA" in the Office Dev Center > Microsoft Office for Developers Forums > Word for Developers section.
I created the two classes, ran his test cases, and it worked perfectly inside Outlook 2007 SP3 32-bit VBA under Windows 7 64-bit. It will most likely work for Access.
Tip: To rename classes, select the class in the VBA 'Project' window, then click 'View' on the menu bar and click 'Properties Window' (or just hit F4).
With his classes, this is what it takes to copy to/from the clipboard:
Dim myClipboard As New vbaClipboard ' Create clipboard
' Copy text to clipboard as ClipboardFormat TEXT (CF_TEXT)
myClipboard.SetClipboardText "Text to put in clipboard", "CF_TEXT"
' Retrieve clipboard text in CF_TEXT format (CF_TEXT = 1)
mytxt = myClipboard.GetClipboardText(1)
He also provides other functions for manipulating the clipboard.
It also overcomes 32KB MSForms_DataObject.SetText limitation - the main reason why SetText often fails. However, bear in mind that, unfortunatelly, I haven't found a reference on Microsoft recognizing this limitation.
-Jim
I couldn't figure out how to use the API using the first Google results. Fortunately a thread somewhere pointed me to this link:
http://access.mvps.org/access/api/api0049.htm
Which works nicely. :)
Easy TWO line code:
It's not so complicated, I don't understand why all solutions found in the net are so complicated.
Sub StoreData()
Set objCP = CreateObject("HtmlFile")
objCP.ParentWindow.ClipboardData.SetData "text", "Some text for clipboard"
End Sub
There are many examples listed here but none seem to cover the direct way of using the API that also works with Access and Excel 32 bit and 64 bit.
I don't want to steal anyone else's work so I'm pointing to an article that has a solution.
https://stackoverflow.com/a/35512118/1898524
Following up on David's idea, if you want to pass in an argument, it has to be double-quoted.
Public Sub SetClipboardText(ByVal Text As String)
Dim QuotedText As String
QuotedText = """" & Text & """"
Set HtmlFileObject = CreateObject("HtmlFile")
HtmlFileObject.ParentWindow.ClipboardData.SetData "text", Eval(QuotedText)
End Sub

Resources