Accessing ScreenTip text - vba

I have a long MS Word doc that has many bookmarks/hyperlinks. The only purpose of the bookmarks is to be able to use the screen tips to view additional information about what is bookmarked.
Is there a way to access this screen tip text, and store it in a variable?
Eventually I will use this to create a macro that will change the displayed text to include the screen tip text (so the information can be printed, when necessary).

Here's how to print-to-console all the Hyperlink ScreenTips in your document:
Sub printScreenTips()
Dim link As Hyperlink
For Each link In ThisDocument.Hyperlinks
Debug.Print link.ScreenTip
Next
End Sub
Note: I'm not aware of a way to add a ScreenTip to a bookmark, but you can add a ScreenTip to the hyperlink that points to a bookmark.

Related

MS Word: Trying to dynamically update a text field when I change pictures

I create scannable QR codes cards in word for users to report problems. Each time I change the QRCode image, I have to change the Caption under the image to match it to the computer we are labeling. Typing this caption takes time, as 9 cards fit on a single page and each has to be updated when we insert/change the image. I'm trying to figure out how to dynamically change the caption each time I change the picture. I am adding an image as an example below. ANY Help would be appreciated.
enter image description here
I have tried looking at VB to set a label and reference the image filename (which us created with the computer name) and just remove the extension, but I can't figure out how to set the properties for the object and dynamically link them. I have little VB.Net scripting and haven't used it in almost 10 years.
Assumning you need a solution for manual data entry into your 9 cards/labels (even though a mailmerge would work better for bulk card/label creation), if you configure each of them with:
a DISPLAYBARCODE field where your image shows the QR code; and
a text content control where your image shows the serial #,
the following ContentControlOnExit macro, placed in the 'ThisDocument' code module of your document or its template will automatically update the QR code in each label/card to match the serial # whenever its content control is exited.
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
With CCtrl.Range.Cells(1).Range
.Fields(1).Code.Text = "DISPLAYBARCODE " & CCtrl.Range.Text & " QR \q 3"
.Fields.Update
End With
End Sub

Focus cursor in a bubble comment created with VBA

I add a new comment in VBA.
Initial = ActiveDocument.ActiveWindow.View.SplitSpecial
Selection.Comments.Add Range:=Selection.Range
ActiveDocument.ActiveWindow.View.SplitSpecial = Initial
This displays the comment in the right margin in a "bubble". The text entry point remains in the document.
How can I get the text entry point inside the comment bubble?
NOTE: If I use SendKeys to add the comment using the ribbon controls, the text entry focus is inside the comment bubble, but I'd rather not use SendKeys as that is liable to go wrong at times.
The most efficient way is to declare a Comment object and initiate it at the time the comment is created in the document. Note, also, that Comments.Add has a parameter for adding text when it's created.
Please also note that the window switching is unnecessary unless you specifically want/need the old Word 2.0 "pane" view (from the time before WYSIWYG existed).
Example:
Dim cmt As Word.Comment
Set cmt = ActiveDocument.Comments.Add(Selection.Range, "test")
cmt.Range.Text = cmt.Range.Text & " More text."

How to find the label of a shape on a Powerpoint slide

Can someone please point me in the right direction to finding the label Powerpoint uses for each shape, active x control, etc... I've researched till I'm blue in the face. Here's what I'm talking about:
I have a very simple slideshow that asks a question in a text box. Just below the question I placed an active x control text box to get the user's answer. All I want to do is take the answer and append it to a text file. Here's the code:
Public Sub WriteAnswerToFile(slideNum As Integer, shapeNum As String)
Dim filePath As String
Dim objFSO As FileSystemObject
Dim objFile As Variant
filePath = "C:\Batch Files\Powerpoint\ButtonPushes\AnswerFile.txt"
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Batch Files\Powerpoint\ButtonPushes\AnswerFile.txt", ForAppending)
objFile.WriteLine (Application.ActivePresentation.Slides(slideNum).Shapes(shapeNum).TextFrame.TextRange)
objFile.Close
End Sub
From each slide, I pass the slide number and the shape designator to the sub routine. The shapeNum is a string because I found that it worked (no better reason than that) for me to pass something like "TextBox 1" as the param. It all works absolutely great if I know the Shape(designator); as in Shape(TextBox1). For the life of me I cannot figure out how to pass the text input by the user into the active x control text box. I have no idea what the designator is. The property sheet for the text input box calls it TextBox1. The Code sheet calls it TextBox1. When I pass that parameter, it prints the question I asked, not the answer, to my text file. I don't know how to call the input text box in my code.
My code prints "How did you hear about us?" to my text file when my code runs with Call WriteAnswerToFile(2, "TextBox 1"). I'm sure that textbox is called textbox 1; it's the first textbox on the slide. I just don't know what Powerpoint labels the user input box.
If there is some sort of Powerpoint scripting or layout page that will define all the shapes in the slidewhow, I'd sure like to be pointed that direction.
You just need to refer to the form part of the Object since this is not a normal shape.
objFile.WriteLine (Application.ActivePresentation.Slides(slideNum).Shapes(shapeNum).OLEFormat.Object.Text)
To clarify from your comment. I think that you have two "Text Box 1". One is "TextBox 1" (note the space) which is the normal textbox and the ActiveX control is "TextBox1" (no space).
If I create a new blank slide and first add a normal text box and then an ActiveX textbox and then run the following code:
For Each shp In Slide2.Shapes
Debug.Print shp.Name
Next shp
The Immediate window will show the following:
TextBox 1
TextBox1
By chance I happened to stumble upon the simplest answer to my question of "finding the label Powerpoint uses for each shape, active x control, etc.."
I am using the Office 16 (Office 365) suite that contains Powerpoint and would not be certain this feature is avaiable to other versions.
On the Home tab in Powerpoint there is an Editing submenu that contains a Select function. As pictured here:
When you click on Select, another submenu appears that shows a Selection Pane function. If you click on that, the selction pane shows up on the right hand of the screen. In that pane you will see all of the objects on the current slide and the names Powerpoint has given to each of them.
It shows there, the discrepancy I was having with calling TextBox(Space)1 and TextBox(NoSpace)1.
This works to be much more expedient for me to grab the name of the shape I want to call in my VBS Scripts.
I am thankful; however, for the time and frustration #Diederik Sieburgh saved me in allowing me to move forward with my project as it is now 2 weeks later that I stumbled upon this information.

How to get the master layout slide name

I'm populating PowerPoint slides with data from an Excel spread sheet. At the moment, I'm accessing the slide using the page number:
Set mySlide = PowerPointApp.ActivePresentation.Slides(1)
Using the Master View option in the UI, you can rename the slide. How can I find the slide using that name?
Thanks,
Carlo.
ActivePresentation.Slides(i).Master.Design.Name
It is the name you see for the theme, in the master view for the slide.
layoutIndex = ActivePresentation.Slides(i).CustomLayout.Index
It is the current layout of the slide in the above theme.
ActivePresentation.Slides(i).Master.Design.Parent.CustomLayouts.Item(layoutIndex).Name
It is the layout name of the currently selected layout of the slide.
it is the VBA, what you can say :-).
Using the Slide.Name property will define the name of the slide and allow it to be called using:
ActivePresentation.Slides("Name")
per the MSDN
So, what I wanted was a way to uniquely identify a PPT slide through VBA. The problem is that I still need to be able to identify that slide if it is copied to another PPT document.
So, what I found I had to do was:
create a text box on each page and hard-code the text to be something like "Slide:Cover" or "Slide:QuarterlyResults", etc.
loop through each slide
find "Slide:" and strip it out to get the page title. That way, if the slide is copied to another PPT document, the name goes with it.
create a Dictionary that uses the Slide.SlideID as the key and the page title as the value.
Then what I do is loop through the slides, get the SlideID, use the Dictionary to get the page title and use a Select statement to map to the proper method to process the slide.
Yeah, I know... it's an icky hack, but it's the only way I could think of doing it.
Thanks for you help,
Carlo.

MS-Word VBA reference identification

I have a custom content control in Microsoft Word from a third party I am trying to resize the width and height of. Normal content control selection via VBA is not working because this control has no Title or Tag. However, if I manually select the object and resize it programmatically using "Selection.ShapeRange.Height = x" or ShapeRange.Width it does work. So to do it all programmatically I need to determine the name of the "selection" without having to manually select it.
Is there a way to "inspect" the complete reference to the currently selected object in word, so we can then get a starting point to work with it in VBA?
It's hard to know what type of object your dealing with. I tested this by inserting a blank ActiveX image control, selecting it and then running the macro. The code has two methods but one is commented out.
Sub FindName()
MsgBox (Selection.Fields.Item(1).OLEFormat.ClassType)
'MsgBox (Selection.InlineShapes.Item(1).OLEFormat.ClassType)
MsgBox (Selection.InlineShapes.Item(1).Field.Index)
MsgBox (Selection.InlineShapes.Item(1).AlternativeText)
'Show current name
MsgBox (Selection.Fields.Item(1).OLEFormat.Object.Name)
'Set new name
Selection.Fields.Item(1).OLEFormat.Object.Name = "Image5"
'Re-display name to show that it changed
MsgBox (Selection.Fields.Item(1).OLEFormat.Object.Name)
End Sub
The result was this: