I have a Visio drawing and I want to be able to Select shapes from it and paste them to other sheets depending on certain variables.
What is the code for selecting the different shapes on the page. I am trying this but it is not working.
Dim vsoSelection As Visio.Selection
vsoSelection.Select Visio.Shape(1), visSelect
What am I missing here?
and also is it possible to get the strings entered into text boxes into Visio?
I am assuming you're getting an error because your vsoSelection object is nothing. So you need to do:
Set vsoSelection = ActiveWindow.Selection
Related
I want to add a chart inside a textbox using VBA in Microsoft word.
I have tried using
ActiveDocument.InlineShapes.AddChart()
API;
with cursor inside the textbox and still it doesn't produce the desired result
Unless you specify where the chart is to be placed it will simply be added to the document. If you had looked at the help text, IntelliSense or the Object Browser you would have seen that the method takes a Range as an argument. To place the chart in a specific location the range is required.
For example:
Set shp = ActiveDocument.InlineShapes.AddChart(Range:=Selection.Range)
I am using Excel 2007. I have a worksheet that contains many shapes. Each shape is linked to a cell on another spreadsheet (i.e., '=Data!$F$5') in order to dispay some text in each shape.
Now, I would like to use the formula in the shapes as a starting point to reference other cells from the worksheet. The idea behind this is to run a macro when the user clicks on the shape to give them additional information in a message box.
I've tried making a string from "ActiveShape.DrawingObject.Formula", but haven't had any success. Does anyone know how to do this or suggest another way of accomplishing this?
Any help is greatly appreciated.
Within the macro that you assigned to the shape(s). You can use
ActiveSheet.Shapes(Application.Caller).name to get the name of the shape
and then ActiveSheet.Shapes.Range(Array(name)) to get the shape reference. Then you can select it and use Selection.formula to get the formula
Copy this and paste it into your macro for the shape and you can see how it works:
Dim name As String
Dim formula As String
name = ActiveSheet.Shapes(Application.Caller).name
ActiveSheet.Shapes.Range(Array(name)).Select
formula = Selection.formula
MsgBox formula
Note: I did try and just do formula = ActiveSheet.Shapes.Range(Array(name)).formula but vba was unhappy with me. So I had to stick to the .Select and Selection.formula
I'm automatically generating a powerpoint slide through VBA, User Forms, and Excel. You run the VBA script in excel, fill out the data, the data goes into cells in excel, then the VBA script pulls the data and puts it into textbox shapes in the slide.
My problem is I want to use different font sizes at different times, so for example 28 pt font for one part and 14 pt for the rest. The problem is that any property changes I make to the textbox applies to all of the text within the shape.
My current workaround is sloppy and is to just generate another textbox over the original and insert spacing in the original so it looks like the larger text is "in" the textbox while it's actually just sitting over a few empty lines set aside.
You can format specific substrings within a string, but it's very cumbersome, for example assuming shp is an object variable representing your textbox:
Sub foo()
Dim shp As Shape
Set shp = ActivePresentation.Slides(1).Shapes("TextBox 3")
shp.TextFrame.TextRange.Text = "Hello, world!"
shp.TextFrame.TextRange.Characters.Font.Size = 14 'applies uniform font to entire shape
shp.TextFrame.TextRange.Characters(1, 5).Characters.Font.Size = 28
End Sub
Example output:
The difficulty of course is working with mixed formats, and I do not think there is any easy solution. It will be up to you to determine what formats you need to "capture", and what subsequently implement the appropriate conditional logic to transfer those formats to the PowerPoint shapes.
One possible alternative -- and this is the route that I would go if I were you -- would be to copy the cell from Excel, and use this method to paste in to PowerPoint. I believe this will create a table consisting of a single cell, in the PowerPoint slide. You will have to make adjustments for size/position, but this should be an order of magnitude easier than trying to capture every possible variation of font formatting:
Sub foo2()
Dim shp As Shape
Dim xl As Object
'Get Excel and copy a specific cell
Set xl = GetObject(, "Excel.Application")
xl.Workbooks("Book35").Sheets("Sheet2").Range("B4").Copy
'Paste that cell in to PowerPoint as a table, preserving formats:
ActivePresentation.Slides(1).Select
Application.CommandBars.ExecuteMso "PasteSourceFormatting"
End Sub
Example output, as copied from the Excel cell:
No need to change the font in excel to reflect in Word. You can do it directly. Just paste the below mentinoed line in Word VBA : -
Activedocument.Shapes("sam").TextFrame.TextRange.Words(1).Font.Size = 28
I need to know is selected shape word art or not.
Shape has property "Type" (returns enum MsoShapeType).
When I insert word art and check this property - it returns msoAutoShape instead of msoTextEffect (with AutoShapeType==msoShapeRectangle).
How can I check that spae is word art (not usual rectangle with textbox) ?
Thanks!
If you select either the overall smartart shape or click into text within the smartart shape or select one of the shapes within the smart art, ActiveWindow.Selection.ShapeRange(1) will return the smartart shape.
So
If ActiveWindow.Selection.ShapeRange(1).HasSmartArt Then
Debug.Print "It's smart art"
End if
[edited]
But as you've pointed out, this is for smartart, not word art. My error, sorry.
There isn't a WordArt shape as such; it's more like any shape that has had WordArt formatting applied to the shape as a whole or to text within the shape. That'd include formatting like glow, reflection, shadow and so on, or could be one of the WordArt presets, pre-selected combinations of these different effects. I've added an example that'll help identify shapes or ranges of text within shape that have these presets applied. I don't see any simple way of checking for user-applied WordArt formats other than looking at each run and each text box for each of the various properties (glow, reflection etc) that might be applied. Unfortunately, there's no WordArtFormat = None to tell us we can ignore it. It's either going to be one of the presets or -2, which can mean any of several things.
Sub WordArtist()
Dim oSh As Shape
Dim oRng As TextRange2
' Has word art formatting been applied to
' entire shape?
Set oSh = ActiveWindow.Selection.ShapeRange(1)
Debug.Print oSh.TextFrame2.WordArtFormat
' Has it been applied to individual chunks of
' text within the shape
For Each oRng In oSh.TextFrame2.TextRange.Runs
Debug.Print oRng.Font.WordArtFormat
Next
' Note:
' A result of -2 for the entire shape could mean
' - No text in the shape; not really word art
' - Mixed formatting
' - Text/shape has had glow/shadow/reflection etc applied
' rather than one of the preset WordArt selections
End Sub
I am struggling to find out how to vertically align textboxes via VBA.
Furthermore, when researching the Autofit feature of Powerpoint, I found quite some posts, that said this can only be changed in the registry, but on my PC, some templates autofit and some don't., Is there some way to turn it off when creating the placeholders in VBA?
Thanks for the help
seba
AutoFit can be turned on/off for shapes that have text frames (ie, that can contain text):
Assuming a reference to the shape in oSh,
oSh.TextFrame.AutoSize = ppAutoSizeNone ' or ppAutoSizeShapeToFitText
' 0 or 1 respectively