I am trying to use vba to save grouped shapes as an image in powerpoint. The "save as picture" function that you can use by right clicking on the group produces high quality images. My attempt to recreate the right-click function produces blurry, low quality images. Is there a way to exactly recreate the right click save as picture instead of export?
ActivePresentation.Slides(1).Select
Call ActiveWindow.Selection.ShapeRange(1).Export( _
"C:\myloction.png", _
ppShapeFormatPNG)
Add optional scaleheight/scalewidth parameters after the ppShapeFormat parameter. The results seem almost random, I don't know exactly what the parms are supposed to relate to, but the bigger the number you feed it, the higher the rez of the exported image.
Related
I have a problem to get a certain amount of shapes in ppt to a certain format. I generate them via nprinting and they are already grouped properly. The problem is that I can´t crop them once their grouped. If they are not grouped I can address each of them individually and crop them the way I want. I need them in picture(u) format in order to be able to crop them. My approach was to cut them and insert them again but as picture. Unfortunately I wasn´t able to cut and paste them via vba with the code below. Does anyone have an idea how to solve this?
Dim myDocument As Object
Set SlidePPT = objPPT.Presentations(FilePPT).Slides(7)
SlidePPT.Select
myDocument.Slides(7).Shapes.SelectAll.Group
Selection.Cut
myDocument.Slides(7).Pictures.Paste
myDocument.Slides(7).Shapes(1).PictureFormat.CropBottom = 200
The alternativ I had in mind was to crop it first and Group it then, but this seems not to work either.
edit: Okay, it seems that the problem with my alternative approach is, that my code just selects all of the shapes but does not group them. Any ideas on that?
Solved it. i just needed to add the range.
myDocument.Slides(7).Shapes.Range.Group
I'm trying to grab the text from inside a shape on a Word document.
Sub textgrab()
MsgBox ActiveDocument.Shapes("Rectangle 85").TextFrame.TextRange.Text
End Sub
I get the error:
Run-time error '-2147024809 (80070057)':
The item with the specified name wasn't found.
In the Word document when I go to the top menu, hit the shape format tab, and in the arrange section, I select 'selection pane', I get a list of all the shapes, 'Rectangle 85' is there.
When I select it, it highlights the box i'm trying to grab the value from.
This is a pdf that I've opened in Word. I'm trying to automate a process that will open a pdf invoice, grab the dollar total, and pull it into Excel.
Solution for those that stumble upon this later. I used the following:
ActiveDocument.ActiveWindow.Panes(1).Pages(1).Rectangles.Item(i).Range
Word can only extract text from Drawing objects. These are inserted in the UI, for example, from Insert/Shapes. Shape.TextFrame.TextRange has no OCR capabilities, so can't be used to get text "embedded" in other kinds of graphic objects, such as an embedded PDF file or a JPG or anything similar.
When uncertain whether a particular Shape supports reading or writing text, right-click it in the UI and see if the menu selection Add Text or Edit Text is available.
Can someone help me with a code for capturing a 250X250 pixcel screen and copying it into clipboard. I would like to paste the image into an excel i can code that part. I have no clue where to start. I have made a code till reframing on the a point where i need the macro to capture.
Dim objviewer3d as viewer3d
Selection1.search("Name="+Textbox1.value+"*,all")
Caita.startcommand("reframe On")
Catia.refreshDisplay=true
Set objviewer3d=catia.activewindow.activeviewer
Objviewer3d.viewpoint3d.zoom=0.017
objviewer3d.update
This is the code i have written. I need the capture code. I Have no clue how to do that. And Last thing I know code to capture full screen and capture to file code. I don't want that.
Thank you
The CATIA method which captures the current window to a file is Window.CaptureToFile:
CATIA.ActiveWindow.ActiveViewer.CaptureToFile catCaptureFormatJPEG,"C:\Temp\Capture.jpg"
This captures the entire window, so to make it 250x250, set the ActiveWindow.Height and .Width to 250 before capturing the image. Then set it back afterwords to it's original size only. Alternatively you can resize the image after you insert it into Excel as a shape.
If you want the tree off you can also call ActiveWindow.Layout = catWindowGeomOnly
I have another challenge. Has anyone tried to intercept the copy/paste events? My goal is to prevent someone from cut/copy/paste a shape that is already on a sheet. If they drag it from a stencil, that is fine. I just can't have them duplicate an existing shape. To make this a bit harder, it is only the shape that I need to prevent. If the want to copy text, that is fine.
We have a order type database that contains items that need to be dropped on a Visio sheet. I cannot use the shapeID because I need to be able to update the shape from the database and I can't write the ID back to the database as it is against security policy. The way that I am tying the two together is a property named shapeKey and that value is provided by the database at the time the shape is dropped.
When a use needs to refresh the sheet from the database, I interate through the shapes, comparing the shapeKey in the shape and in the database. if there is a match, I do an update of the other properties. If there is no match, I want to delete the shape. if a user copies a shape, the shapeKey will also be duplicated and that causes problems. Lastly, they can add their own shapes from stencils and those shapes must be excluded from the delete process
I have two options:
Disable shape cut/copy/paste
Intercept the copy/cut and when they paste, change a property so that I know that it was a user pasted shape. This is preferred because it is more user friendly
I just thought if another way I that might work. Is there a way to lock the shapes to prevent the copy? If there is a lock, would that also lock the location? The user needs to be able to most the shapes around.
I thought about capturing the event but I could not find the event codes to look for. I cannot install the Visio SDK which has the Event monitor. The monitor might have shown me the code. Here is some pseudo code as to what I think would be the flow.
option 1
if select item is a shape then
msgbox "shape copying verboten. please us the stencil"
clear selected item
option 2
capture the paste event
if selected item is a shape then
vsoShape.Cells("Prop.ShapeKey").Formula = Chr(34) & "protect" & Chr(34)
Layers might work. All the database controlled shapes can be on one layers and all the user shapes on another but I haven't worked with layers before. would that work? How can I be sure that any shape pasted goes onto the user layer?
Thanks all! I did find a solution and it was really elegant. I found the idea here and changed it to what I needed:
Shape added event: https://msdn.microsoft.com/en-us/library/office/ff767288.aspx
Here is what I came up with:
Private Sub Document_ShapeAdded(ByVal vsoShape As Visio.IVShape)
If vsoShape.CellExistsU("Prop.ShapeName", 0) Then
vsoShape.CellsU("Prop.ShapeName").Formula = Chr(34) & "ShapeName" & Chr(34)
End If
End Sub
The interesting thing is that it doesn't fire if I add the shape via VBA. That is perfect for what I need but I would have thought that dropping a shape is adding a shape. I am only looking for one property because not all shapes on the stencils come from a database and for those objects, I don't need to do anything.
It was not the solution that I expected but it works really well.
Visual Studio 2010, .NET 4, VB.NET
Hello,
I am writing a little program to convert LaTeX snippets to images which can be pasted into whatever program one can paste images into. It's working alright but the next obvious step is to include the source LaTeX code as a piece of metadata in the image so that the results can be modified without having to retype everything.
I have succeeded in adding a title PropertyItem with the latex encoded as an ASCII byte array as its value (id=800, type=2, value=System.Text.Encoding.ASCII.GetBytes(codestring)). I verify that the PropertyItem is really there before trying to put the image on the clipboard.
Then I do Clipboard.SetImage(myImage). The result is all of the PropertyItems are removed (my title plus anything else that was there)! I check this by doing MsgBox(Clipboard.GetImage.PropertyItems.Count.ToString) which gives zero.
This makes me very sad. Anyone know what's up?
Thanks in advance!
Brian
Update: I have figured out how to move the image onto the clipboard and then back off while preserving the PropertyItems like so:
Format = DataFormats.GetFormat(GetType(Image).FullName)
Dim dataObject As New DataObject
dataObject.SetData(Format.Name, image)
Clipboard.SetDataObject(dataObject)
Dim copiedImage As Image = CType(Clipboard.GetDataObject.GetData(Format.Name), Image)
This way, the copiedImage has the same PropertyItems as the original. However, new problem:
Other programs don't recognize what's on the clipboard as an image anymore, which defeats the whole purpose. I.e., if I put an image on the clipboard this way, when I try pasting into some context that accepts pasted images, nothing happens.
What to do?!
I believe the Windows clipboard image has no metadata. If you change the format of the image to add metadata, it is no longer a clipboard image. If the other programs can accept it, you could copy and paste the image file (instead of the image) to the clipboard, and the metadata will of course be intact when it's read by the target app.
Have you tried Clipboard.SetData or Clipboard.SetDataObject? SetImage only copies the image in bitmap format, so I am not surprised that it strips the property items. You might try:
Clipboard.SetData(DataFormats.EnhancedMetafile, myImage)
or
Clipboard.SetData(DataFormats.MetafilePict, myImage)