Decompose lines of standard powerpoint shape - powerpoint

I would like to split a standard PowerPoint shape into separate lines so that I can have full control over how and when they appear when using animations. Thus, I would like to see that the shape on top (a standard PowerPoint shape) is decomposed in the one below (without the space betwen the lines.
I hope somebody has some creative ideas.

This may help get started. Look up the docs on the various properties/methods for more information.
Sub thing()
Dim oSh As Shape
Dim x As Long
Dim pointsArray()
Set oSh = ActiveWindow.Selection.ShapeRange(1)
With oSh
Debug.Print .Nodes.Count
With .Nodes
For x = 1 To .Count
Debug.Print "X = " & .Item(x).Points(1, 1)
Debug.Print "Y = " & .Item(x).Points(1, 2)
Next
End With
End With
End Sub

Related

Display Images from a File into Pictureboxes

I have a folder called
App.Path & "\Images"
Inside of it I have 5 Images and in my Form I have also 5 Pictureboxes. Now my question is, How can I display them all one PictureBox per Image at a time? heres is my code so far
Picture1.Picture = LoadPicture("Path")
Heres what I've done so far
Dim c As Control
Dim ImageLink As String
With vs1
For Each c In Form1
For i = 1 To .Rows - 1
If Len(ImageLink) > 0 Then ImageLink = ImageLink
Debug.Print c.Picture
Debug.Print .TextMatrix(i, .ColIndex("Image"))
MsgBox .TextMatrix(i, .ColIndex("Image"))
c.Picture = LoadPicture("C:\Users\paul\Desktop\Gondola Monitoring System\Image\" & .TextMatrix(i, .ColIndex("Image")))
Next
Next
End With
Form1.Show
I try to write the filename in flexgrid and call it in each control.
TYSM for help
Picture1.Picture = LoadPicture(App.Path & "\Images\file1.jpg")
Picture2.Picture = LoadPicture(App.Path & "\Images\file2.jpg")
Picture3.Picture = LoadPicture(App.Path & "\Images\file3.jpg")
Picture4.Picture = LoadPicture(App.Path & "\Images\file4.jpg")
Picture5.Picture = LoadPicture(App.Path & "\Images\file5.jpg")
If this doesn't provide you with what you need, please provide more details on your requirements.
EDIT
Your code isn't going to work. You are looping over all the controls, which will include any buttons, labels, etc, in addition to your picture controls, and for each control you are looping through all the rows of your grid. One better approach would be to define the picture controls as an array (starting index from 1 to match your grid for loop), then the for index is used so that the grid rows and picture indexes match. Something like this:
With vs1
For i = 1 To .Rows - 1
Picture1(i).Picture = LoadPicture("C:\Users\paul\Desktop\Gondola Monitoring System\Image\" & .TextMatrix(i, .ColIndex("Image")))
Next
End With

2 different color text in one cell

We are putting together a new standard signature using vbs for Outlook.
Everything looks great but design would like the phone numbers to look like the attached image. The "O" for office # in Orange and then the number in blue, the "C" for cell # in Orange and then the number in blue.
I can get the entire cell to be one color, but I don't see how to do 2 colors.
The signature is in a table with the logo in one cell that has 5 rows merged and then the other side has 5 rows.
Here is some of my code:
strName = objUser.FullName
strTitle = objUser.Title
strPhone = objUser.telephoneNumber
strMobile = objUser.mobile
strOffice = "O "
strCell = "C "
objTable.Cell(3,2).Range.Font.Name = "Lato"
objTable.Cell(3,2).Range.Font.Size = "12"
objTable.Cell(3,2).Range.Text = strOffice & strPhone & " " & strCell & strMobile
Start recording a macro do it manually by editing the in the cell or the formula bar. Stop the macro and step into it to get all the colors. I stuck to the main colors on the bottom of the pallet. You'll may have to track ThemeColor, TintAndShade and ThemeFont depending on the colors you choose.
This should get you started
Public Sub AddLogo(r As Range)
Dim i As Integer
Dim ColorArray
ColorArray = Array(-16777024, -16776961, -16727809, -16711681, -11480942, -11489280, -1003520, -4165632, -10477568, -6279056)
r = "Excel Magic"
For i = 0 To UBound(ColorArray)
With r.Characters(Start:=(i + 1), Length:=1).Font
.Color = ColorArray(i)
End With
Next
End Sub
Usage:
AddLogo objTable.Cell(3,2)

Partition powerpoint lines into different objects

I have many power point slides and each slide has many lines but all those lines are in the same objects. I want now to add some animation including appears for each line with click.
How I can partition the lines in each slide such that every line will be in its own object
Note, I am using powerpoint 2010
Thanks,
AA
This isn't perfect; you'll need to add more code to pick up ALL of the formatting from the original text, but it's a start. Click within the text box you want to modify, then run the TEST sub. Once it's adjusted to your taste, it's a fairly simple matter to extend it to act on every text box in the entire presentation (though not tables, charts, smartart, stuff like that)
Sub Test()
TextBoxToLines ActiveWindow.Selection.ShapeRange(1)
End Sub
Sub TextBoxToLines(oSh As Shape)
Dim oSl As Slide
Dim oNewShape As Shape
Dim oRng As TextRange
Dim x As Long
With oSh
Set oSl = .Parent
With .TextFrame.TextRange
For x = 1 To .Paragraphs.Count
Set oRng = .Paragraphs(x)
Set oNewShape = oSl.Shapes.AddTextbox(msoTextOrientationHorizontal, _
oRng.BoundLeft, oRng.BoundTop, oRng.BoundWidth, oRng.BoundHeight)
With oNewShape
.TextFrame.AutoSize = ppAutoSizeNone
.Left = oRng.BoundLeft
.Top = oRng.BoundTop
.Width = oSh.Width
.Height = oSh.Height
With .TextFrame.TextRange
.Text = oRng.Text
.Font.Name = oRng.Font.Name
.Font.Size = oRng.Font.Size
' etc ... pick up any other font formatting you need
' from oRng, which represents the current paragraph of
' the original text
' Bullets, tabs, etc.
End With
End With
Next
End With
End With
oSh.Delete
End Sub

How to get the Shape Clicked without Application.Caller

How can I retrieve the shape that was clicked to run a macro, without using Application.Caller?. Its name or the shape itself as an object.
I cant use Application.Caller because if the shape name is bigger than 30 characters, it retrieves only the first 30 characters.
Maybe there is an API that could retrieve the Sape object?
Edit:
I don't want to loop shapes in sheet. Looping throug all shapes in the workbook takes too much time.
I can not rename the Shapes.
Thanks
Can you rename the Shape objects in your Worksheet?
Private Sub Workbook_Open()
Dim shp As shape
Dim i As Integer
For Each shp In ThisWorkbook.Sheets(1).Shapes
shp.Name = "Shape" & Format(i, "0000")
i = i + 1
Next shp
End Sub
Alternatively, you could manually set the .OnAction property of each shape to pass the shape name to your function:
Sub RenameShapes2()
Dim shp As shape
Dim i As Integer
For Each shp In ThisWorkbook.Sheets(1).Shapes
shp.name = "Shape" & "abcdefghijklmnopqrstuvwxyz0123456789_" & Format(i, "0000")
shp.OnAction = "'userFunction """ & shp.name & """'"
i = i + 1
Next shp
End Sub
Sub userFunction(name As String)
MsgBox name
End Sub
This allows you to have Shape names over 30 characters in length. It's kinda ugly though

Using VBA to change Picture

I am trying to use VBA to automate the Change Picture function when you right click a Shape in Excel/Word/Powerpoint.
However, I am not able to find any reference, can you assist?
So far as I know you can't change the source of a picture, you need to delete the old one and insert a new one
Here's a start
strPic ="Picture Name"
Set shp = ws.Shapes(strPic)
'Capture properties of exisitng picture such as location and size
With shp
t = .Top
l = .Left
h = .Height
w = .Width
End With
ws.Shapes(strPic).Delete
Set shp = ws.Shapes.AddPicture("Y:\our\Picture\Path\And\File.Name", msoFalse, msoTrue, l, t, w, h)
shp.Name = strPic
shp.ScaleHeight Factor:=1, RelativeToOriginalSize:=msoTrue
shp.ScaleWidth Factor:=1, RelativeToOriginalSize:=msoTrue
You can change the source of a picture using the UserPicture method as applied to a rectangle shape. However, you will need to resize the rectangle accordingly if you wish to maintain the picture's original aspect ratio, as the picture will take the dimensions of the rectangle.
As an example:
ActivePresentation.Slides(2).Shapes(shapeId).Fill.UserPicture ("C:\image.png")
'change picture without change image size
Sub change_picture()
strPic = "Picture 1"
Set shp = Worksheets(1).Shapes(strPic)
'Capture properties of exisitng picture such as location and size
With shp
t = .Top
l = .Left
h = .Height
w = .Width
End With
Worksheets(1).Shapes(strPic).Delete
Set shp = Worksheets(1).Shapes.AddPicture("d:\pic\1.png", msoFalse, msoTrue, l, t, w, h)
shp.Name = strPic
End Sub
what I do is lay both images on top of eachother, and assign the macro below to both images. Obviously i've named the images "lighton" and "lightoff", so make sure you change that to your images.
Sub lightonoff()
If ActiveSheet.Shapes.Range(Array("lighton")).Visible = False Then
ActiveSheet.Shapes.Range(Array("lighton")).Visible = True
Else
ActiveSheet.Shapes.Range(Array("lighton")).Visible = False
End If
End Sub
What I've done in the past is create several image controls on the form and lay them on top of each other. Then you programmatically set all images .visible = false except the one you want to show.
In Word 2010 VBA it helps to change the .visible option for that picture element you want to change.
set the .visible to false
change the picture
set the .visilbe to true
that worked for me.
I tried to imitate the original function of 'Change Picture' with VBA in PowerPoinT(PPT)
The code below tries to recover following properties of the original picture:
- .Left, .Top, .Width, .Height
- zOrder
- Shape Name
- HyperLink/ Action Settings
- Animation Effects
Option Explicit
Sub ChangePicture()
Dim sld As Slide
Dim pic As Shape, shp As Shape
Dim x As Single, y As Single, w As Single, h As Single
Dim PrevName As String
Dim z As Long
Dim actions As ActionSettings
Dim HasAnim As Boolean
Dim PictureFile As String
Dim i As Long
On Error GoTo ErrExit:
If ActiveWindow.Selection.Type <> ppSelectionShapes Then MsgBox "Select a picture first": Exit Sub
Set pic = ActiveWindow.Selection.ShapeRange(1)
On Error GoTo 0
'Open FileDialog
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Picture File", "*.emf;*.jpg;*.png;*.gif;*.bmp"
.InitialFileName = ActivePresentation.Path & "\"
If .Show Then PictureFile = .SelectedItems(1) Else Exit Sub
End With
'save some properties of the original picture
x = pic.Left
y = pic.Top
w = pic.Width
h = pic.Height
PrevName = pic.Name
z = pic.ZOrderPosition
Set actions = pic.ActionSettings 'Hyperlink and action settings
Set sld = pic.Parent
If Not sld.TimeLine.MainSequence.FindFirstAnimationFor(pic) Is Nothing Then
pic.PickupAnimation 'animation effect <- only supported in ver 2010 above
HasAnim = True
End If
'insert new picture on the slide
Set shp = sld.Shapes.AddPicture(PictureFile, False, True, x, y)
'recover original property
With shp
.Name = "Copied_ " & PrevName
.LockAspectRatio = False
.Width = w
.Height = h
If HasAnim Then .ApplyAnimation 'recover animation effects
'recover shape order
.ZOrder msoSendToBack
While .ZOrderPosition < z
.ZOrder msoBringForward
Wend
'recover actions
For i = 1 To actions.Count
.ActionSettings(i).action = actions(i).action
.ActionSettings(i).Run = actions(i).Run
.ActionSettings(i).Hyperlink.Address = actions(i).Hyperlink.Address
.ActionSettings(i).Hyperlink.SubAddress = actions(i).Hyperlink.SubAddress
Next i
End With
'delete the old one
pic.Delete
shp.Name = Mid(shp.Name, 8) 'recover name
ErrExit:
Set shp = Nothing
Set pic = Nothing
Set sld = Nothing
End Sub
How to use:
I suggest you to add this macro into the Quick Access Toolbar list.
(Goto Option or Right-click on the Ribbon menu))
First, select a Picture on the slide which you want to change.
Then, if the FileDialog window opens, choose a new picture.
It's done. By using this method, you can bypass the 'Bing Search and One-Drive Window' in ver 2016 when you want to change a picture.
In the code, there might(or should) be some mistakes or something missing.
I'd appreciate it if somebody or any moderator correct those errors in the code.
But mostly, I found that it works fine.
Also, I admit that there are still more properties of the original shape to recover - like the line property of the shape, transparency, pictureformat and so on.
I think this can be a beginning for people who want to duplicate those TOO MANY properties of a shape.
I hope this is helpful to somebody.
i use this code :
Sub changePic(oshp As shape)
Dim osld As Slide
Set osld = oshp.Parent
osld.Shapes("ltkGambar").Fill.UserPicture (ActivePresentation.Path & "\" & oshp.Name & ".png")
End Sub
I'm working in Excel and VBA. I can't overlay images because I have multiple sheets of a variable number and each sheet has the images, so the file would get huge if, say 20 sheets had all 5 images I want to animate.
So I used a combination of these tricks listed here:
1) I inserted an RECTANGLE shape at the location and size I wanted:
ActiveSheet.Shapes.AddShape(msoShapeRectangle, 1024#, 512#, 186#, 130#).Select
Selection.Name = "SCOTS_WIZARD"
With Selection.ShapeRange.Fill
.Visible = msoTrue
.UserPicture "G:\Users\ScotLouis\Documents\My Spreadsheets\WordFind Wizard\WordFind Wizard 1.jpg"
.TextureTile = msoFalse
End With
2) Now to animate (change) the picture, I only need to change the Shape.Fill.UserPicture:
ActiveSheet.Shapes("SCOTS_WIZARD").Fill.UserPicture _
"G:\Users\ScotLouis\Documents\My Spreadsheets\WordFind Wizard\WordFind Wizard 2.jpg"
So I've accomplished my goal of only having 1 picture per sheet (not 5 as in my animation) and duplicating the sheet only duplicates the active picture, so the animation continues seamlessly with the next picture.
![Please find attached code.
First create a shape in PPT and run the code]1

Resources