Read image from shape into userform image - vba

I am looking to read image from word shape and load it in userform image1 box
explain: its a word shape, and I fill it with picture rather than color
This not working, run-time error 9 object variable or with block variable not set
Word VBA
Image1.Picture = LoadPicture(ThisDocument.Shapes("Shape1").LinkFormat.SourceFullName)
Sample file
enter link description here

Related

Detect if selected shape / table is in edit mode with VBA?

I'm trying to write a PowerPoint VBA macro that would act differently whether a shape is merely selected or is in edit mode (i.e. the cursor to edit the text is present, see image).
Is there a way to check this using VBA in PowerPoint? I haven't been able to find on this anything so far
My ultimate goal being:
If just the shape is selected, the macro will align the shape left
If the shape is in edit mode, the macro will align the text left (and leave the shape where it is)
Any help would be appreciated
Best
You can do this by using Selection.Type. If it returns 2, the shape is selected. If the insertion point is in the text, it will return 3:
Sub DetectShapeOrText()
MsgBox ActiveWindow.Selection.Type
End Sub
PpSelectionType enumeration (PowerPoint)

Call a subprocedure with an input argument inside a shape

My goal is to call a macro (with input of specific information from the shape) inside a shape in the MS VISIO application.
The macro is to open a PDF datasheet of the specific shapes (the element in my block diagram).
I have an idea to trigger the macro from the specific shape, which is inserting action section and using runaddon function to run the subprocedure (using shell to open a specific PDF file).
Question:
How do I pass an argument (type of string) of the shape (in my case it is a PDF file name for this shape) to the subprocedure? If that can be achieved, I can open each shape's corresponding datasheet.
How do I save the input argument value (type string) inside each shape?
And how do I call them inside VBA subprocedure?
Visio has hyperlinks. You can just add a hyperlink to your shape pointing to your PDF, and the menu item action as well as click behavior will be added automatically.
So, click Ctrl+K to add a hyperlink, or use "insert" menu.
You can also add hyperlink programmatically, or by linking to a data source (like excel). Also you can build URL of the link as a formula, out of shape data, like shape text.
If you still want to do it with vba macro, you can try CALLTHIS function: https://learn.microsoft.com/en-us/previous-versions/office/developer/office-2003/aa212649(v=office.11)?redirectedfrom=MSDN#example-1

Powerpoint VBA to search for and change colour/highlight keywords in textbox

I am very new to VB and am exploring this method to simplify mundane manual work process of highlighting certain text in Powerpoint textboxes.
My intention is for VBA to search for keywords in the textbox, then changes the colour of this line and also a few other lines. e.g. search for the line that contains the word "video", if it returns that line 7 contains this word, I want to change the colour of line 7 and maybe lines 3, 10 and 11 to red colour.
Since your question is generic, We can only give a generic response.
First thing you need to know about VBA in powerpoint for your issue is that you need to access things like objects. You'll first need to access the current Slide and Shape your textbox is in. In this example, Let's assume the textbox you want to access is in the first slide, in the first shape:
Set oTextbox = ActivePresentation.Slides(1).Shapes(1)
With oTextbox
text = .TextFrame.TextRange.Characters.Text 'To access the textbox text.
If InStr(1,text,"some_text")
.TextFrame.TextRange.Font.Color.RGB = [255 0 0] 'To change the color of a textbox.
End If
End With
.TextFrame.TextRange.Characters.Text accesses the shape's text.
To search for a given text in the textbox, you can use the InStr
command to see if the text you want is in your textbox.
.TextFrame.TextRange.Font.Color.RGB accesses the text's color.
This is at least a start for you.

How do I change the value of the SlideMaster.Height in PowerPoint 2016 VBA?

I'm trying to automate the process of changing the height in the Slide Size dialog in the Slide Master system with VBA. When I try to change it, VBA informs me that I'm not permitted to assign a value to ActivePresentation.SlideMaster.Height because it is read-only.
I've studied the ActivePresentation object tree and have figured out to acquire the height value (with ActivePresentation.SlideMaster.Height), but the following line results in a Compile Error:
ActivePresentation.SlideMaster.Height = 1189
Changing the SlideHeight with...
ActivePresentation.PageSetup.SlideHeight = 1189
does change the height of the slide, but it doesn't have the same effect as changing the height through the Slide Master system. The primary question at this stage is if it's possible to change ActivePresentation.SlideMaster.Height with VBA, or is the Read-Only status immutable?
Sub test()
ActivePresentation.SlideMaster.Height = 1189 'Compile Error...can't assign to read-only property
ActivePresentation.PageSetup.SlideHeight = 1189 'Changes the height of the slides, _
but doesn't change the size of text within Shape elements like I need it to do.
End Sub
Here's some background...
Through a bit of trial and error, I've determined that if I change the dimensions of the slides using the slide master, the default text for Shapes is set how I want it (at pitch 18). If I don't change the dimensions in the Slide Master, the text for Shapes remains at 31. Even if a new shape is created, the font is changed to 18 and that shape is set as the default shape, if text is pasted onto the slide (with CTRL-v or Paste Special-Unformatted Text), the shape that gets created has a text-size of 31.
Just to be clear, if the default is set to 18 and I create another new Shape via Insert>Shapes, then that new shape is automatically set to 18. It's only when I paste text (using either CTRL-v or Paste Special - Unformatted) directly on the slide does it become 31.
The only thing that does what I want is making a slight change to the Slide Master Slide Size. Changing the height from 1188 to 1189 forces all of the shapes on all of the slides to go from 31 to 18. Any new text that gets pasted in the slide comes in as a shape containing 18 text.
The reason I'm posting this on Stack Overflow and not on Super User is because I have to automate this change...we have thousands of presentations to modify.

Save all Pictures of slide into single JPG image using VBA

I would like to do the following in VBA powerPoint:
I have a powerPoint with six pictures on it. Ideally I would like to group the six pictures to create one new picture as a .jpg, then export the .jpg picture to a file. After exporting the photo, I would like to then delete the 6 individual pictures so I can import the single .jpg picture.
I have used this to start: Save all Shapes of slide into single JPG image . I understand the comment, but do not know how to execute it.
If there is a better way to do this, please share.
Thank you!
This will convert the currently selected shapes to a PNG, paste it back onto the slide and delete the original shapes.
You may want to modify this to ensure that something is selected and quit gracefully if not, or if it's just for your own use, let PPT/VBA scold you if you forget to select something.
Sub ConvertSelectionToImage()
Dim oShapes As ShapeRange
Dim oGroup As Shape
Dim oSingleShape As Shape
' Get a reference to the selected shapes
Set oShapes = ActiveWindow.Selection.ShapeRange
' Group them so we can later pick up their coordinates
Set oGroup = oShapes.Group
' copy to clipboard
oGroup.Copy
' paste from clipboard as PNG to retain transparency
Set oSingleShape = ActiveWindow.Selection.SlideRange.Shapes.PasteSpecial(ppPastePNG)(1)
' Position the pasted PNG to match original shapes
With oSingleShape
.Left = oGroup.Left
.Top = oGroup.Top
End With
' And delete the original shapes
oGroup.Delete
End Sub