Object name changes between Office 2007 and 2003 - vba

I had assigned object names to objects in a 2007 Powerpoint file for automation purposes. I ran the automated code in another machine which has office 2003 and found that the object names are dynamically changing there hence the automated code throws an error.
I tried renaming the objects again in that machine using VBA and it works while debugging. But the error throws up when I rerun the automation code.
Is it a compatibility issue between the 2 versions or something else?

that was my problem with differentversions of Word. Generally, Code to the highest version of PowerPoint might not be supported under earlier versions. but sometimes the code works but the method which it refereed may be caused the problem.
I recommend use late binding (... As Object) to solve the problem
revision with an example:
The difference is that you bind the object library in code at run-time. You don't use Tools-References. something like that:
Sub ppt()
Dim olApp As Object
Set olApp = CreateObject("PowerPoint.Application")
End Sub

By "object names", do you mean shape names? Ie the shape's .Name property? This does seem to be buggy.
Consider using tags on the shapes you need to work with. For example, assuming a reference to your shape in oSh, instead of using oSh.Name = "Remember me", do something like:
oSh.Tags.Add "ShapeName","RememberMe"
Then when you need to get a reference to a shape, use a function like:
Function ShapeNamed(oSl as Object, sName as string) as Shape
Dim oSh as Shape
For Each oSh in oSl.Shapes
If oSh.Tags("ShapeName") = sName Then
Set ShapeNamed = oSh
Exit Function
End If
Next
End Function
oSl is declared as Object rather than Slide so you can pass the function Slides, Masters, Layouts, etc.

Related

Add clickable checkbox to powerpoint slide on Mac

I want to add a clickable checkbox (one or more) to a PowerPoint presentation slide. I'm using MacOS and Microsoft Office 365.
I guess that it is possible to do using macros created with VBA, but I have no idea what code needs to be created for this.
I would be very grateful if you would share the necessary code or suggest me another relevant ways to create clickable checkboxes in pptx under the Mac.
Checkboxes, labels, textboxes etc are all ActiveX features, and since ActiveX isn't supported on the Mac version of Office or in MacOS generally, you can't do this the way you would in Windows versions of Office.
You might be able to fake it by adding drawn rectangles and assigning a Run Macro action setting to each of them.
This page on the PPT FAQ that I maintain explains how to write the macro.
Determine which shape was clicked
https://www.pptfaq.com/FAQ00141_Determine_which_shape_was_clicked.htm
TL;DR - here's some sample code. This runs on both Windows and Mac (where bugs in PPT's VBA model force it to be more complicated than it would be otherwise):
Sub DoSomethingTo(oSh as Shape)
Dim oSl as Slide
Dim oShTemp as Shape
' oSh.Parent returns a valid reference to the shape's host slide:
Set oSl = ActivePresentation.Slides(oSh.Parent.SlideIndex)
' and oSh.Name works:
MsgBox oSh.Name
' So we use those two bits to get a reference
' to the clicked shape like so
Set oShTemp = oSl.Shapes(oSh.Name)
With oShTemp
.TextFrame.TextRange.Text = oSh.Name
' and whatever else you want to do with the shape
End With
End Sub

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 Call a Subroutine From Another Object

I am not entirely sure if this is possible, but assuming with us being able to set object references I don't see why not.
To start off, the object that contains the subroutine in question is Excel itself. I am wanting to call one of Excel's VBA subroutines using a different program's VB6 script editor.
I have tried the following without success, but hopefully you can see what I am trying to accomplish here:
Sub Excel_Test()
Dim appXL As Object
Set appXL = GetObject(, "Excel.Application")
Call appXL.Project1.Module1.Test()
End Sub
Obviously this code is not working - but what would be the proper Syntax (if one exists) to call the Macro Test, located in Module1 contained in Excel's object?
You can automate other instances of excel if you identify them by some criteria like the workbook name,
try like
Code:
set otherinstance = getobject(,"fullpath\filename.xls")
otherinstance.application.run "macroname"

Excel vba to modify Catia v5 model properties

I am a novice when it comes to CATIA, but I have a fair amount of experience with VBA in excel. I am trying to develop an excel macro that goes through the all the parts in a catia assembly, renames them by splicing the text where i want, and then reorder them (alpha-numeric ascending order). I believe I can write the algorithm for the actual splicing, renaming, reordering bit. What I am struggling with is actually operating Catia using excel. There is not a lot of information on the internet. I have ticked all the boxes in the references section that start with CATIA. I have written this so far:
Dim CATIA as object
Set CATIA = Getobject(,"CATIA.Application")
Dim oMyDoc as Document
Dim oCurrentProd as Product 'I assume the individual parts within CATIA are_
referenced as products?
Set oMyDoc = CATIA.ActiveDocument
If I try and run just the above code, I get an error saying 'Class doesn't support Automation'. Which means my basics are wrong. Would appreciate help on this and any other information that would enable me to complete my task. Thanks.
When running a code from CATIA in VBA, some objects gets an error when they are properly typed. Try declaring those objects without a type or as a variant.
Dim CATIA as 'object
Set CATIA = Getobject(,"CATIA.Application")
Dim oMyDoc as 'Document
Dim oCurrentProd as 'Product
Set oMyDoc = CATIA.ActiveDocument
or
Dim CATIA as variant
Set CATIA = Getobject(,"CATIA.Application")
Dim oMyDoc as variant
Dim oCurrentProd as variant
Set oMyDoc = CATIA.ActiveDocument
I recommend you to first declare them properly typed so you can see the object's methods and properties and afterwards change it to variant

how to get access a chart by name

Using Word VBA, is it possible to access/get a reference to a chart object using the chart name?
In the Word interface, you can open the "selection pane", and specify a name for a chart. I would like to use that name property to access the chart in VBA.
If I can't use the name, I have to get a reference through a more cumbersome route by locating the chart as part of a range's InlineShape collection.
Set MyChart= wrdApp.Selection.InlineShapes(1).Chart
But that is very tedious, so it would be great to be able to navigate straight to the chart based on the name...
InlineShape-objects do not have a name property. If you convert them to shape objects they do, but you would still have to address them with InlineShapes(index) for the conversion:
Sub ShapeTest()
Dim oShp As Shape
If ThisDocument.InlineShapes.Count > 0 Then
Set oShp = ThisDocument.InlineShapes(1).ConvertToShape
MsgBox "Shape name = " & ThisDocument.Shapes(oShp.Name).Name
End If
Set oShp = Nothing
End Sub
(The sample is quite meaningless, but you get the idea)
EDIT:
Just checked the online documentation for InlineShape and it seems that the InlineShape object as a Name property in Word 2013 and later. Which version are you running? I only have access to Word 2010 where my ansewer above is true.