I'm currently working with PowerPoint in VB.NET and having a bit of trouble getting a slide to have an individual background. Using the SlideMaster method changes all slide in the presentation and I want only one to be affected can anyone offer any advice? I'm not in a position to post code at the moment, but I will comment with some when I can, if no one can help.
PS Using the Background.Fill.UserPicture method doesn't seem to be working, but I'm not sure why...
Sometimes the macro recorder in older versions is a blessing, in its own odd way. Here's what PPT 2003 gives you when you record the act of setting a background to a picture for a given slide (after I've commented out the bits that don't have much/any effect on things):
With ActiveWindow.Selection.SlideRange
.FollowMasterBackground = msoFalse
'.DisplayMasterShapes = msoTrue
With .Background
.Fill.Visible = msoTrue
'.Fill.ForeColor.RGB = RGB(255, 255, 255)
'.Fill.BackColor.SchemeColor = ppAccent1
'.Fill.Transparency = 0#
.Fill.UserPicture "C:\Documents and Settings\Me\My Documents\My Pictures\photo.jpg"
End With
End With
UserPicture is the way to set the picture fill, as you see here; but you have to set .FollowMasterBackground to False, else it ignores your fill settings.
Related
I am using the Fill.UserPicture property to change the image displayed in a shape but the image doesn't get redrawn/refreshed. If I manually right-click the shape and do Change Picture and then paste in the same path and file name (copied from the VBA) it works.
this SO page says that it worked for them
Any reason why this might be?
I have tried making the Fill not visible first. I'm using Excel 2016.
EDIT: Added the code
Dim shpImage As Shape
Dim sNewImagePathAndName As String
sNewImagePathAndName = GetImageFromWebsite(sLineNumber)
Set shpImage = ThisWorkbook.Worksheets("Images").Shapes("shpTemplateImage")
With shpImage
If sNewImagePathAndName <> vbNullString Then
.Fill.Visible = msoFalse
.Fill.UserPicture PictureFile:=sNewImagePathAndName
Debug.Print sNewImagePathAndName
.Fill.Visible = msoTrue
End If
End With
Example of sNewImagePathAndName: "H:\My Documents\Project One\Development\Visual Stock Pack\TS03N50NBLK_Large_F_1.jpg"
'I have tried to apply a color by vba with this code to a shape
.Fill.ForeCorlor.RGB = RGB(250, 0, 0)
'but soon I realize this color stay in memory* even though I tried to clear it with
.Fill.Transparency = 0.5 'Or
.Fill.Visible = msoFalse
'I do not want to use .Fill.ForeColor.TGB = RBB(255, 255, 255)
to set another color as it may overlay and block other content
*In memory: I mean when I applied a color to a shape and try to clear it with the above method, The next time I target shape with RGB(230,0,0), this shape that I thought has been previously set the color and clear still get targeted.
Appreciate for any help on this
G
I was trying to write a VBA macro to align an image to the top right corner of the page and set text wrapping to "Behind Text" and "Fixed Position on Page."
Normally I select the image and do all those settings through dialog boxes. But it gets tedious after a while. I'm wondering if there's a way to do it programmatically. I'm hoping I could open the page header, paste in my header image, and then click a macro button to have the macro align the still-selected image.
I tried recording a macro of my operations, but the macro did not record any of my dialog actions (behind text, fixed page position, etc). So that method provided no solution. I tried it with images inside and outside of page headers, without success.
Is it possible to have some VBA code align the currently selected image object? Ideally, I would open up the page header, paste in my header image, and run a VBA macro to do the four operations above (behind text, fixed position on page, align top to page, align right side to page). I'm hoping someone can show me how or point me to some documentation or examples that show how to do it.
UPDATE
I couldn't post to the forum for some reason, so I worked on the problem for a couple of days and finally pieced together this solution for the next person. I wish I knew where to look in a manual or tutorial for this kind of thing.
But the only way seems to be to cobble solutions together from forums on the net. Here's my contribution! :-)
Sub AlignTopRight()
' Paste an image into Word so it is still selected
' Then invoke this macro to align it to the top right corner
' And to set it behind text, fixed position on the page
Application.ScreenUpdating = False
Dim Shp As Shape
On Error Resume Next
'I'm not sure if this block is required, but it works
Set Shp = Selection.InlineShapes(1)
If Not Shp Is Nothing Then
Set Shp = Selection.InlineShapes(1).ConvertToShape
Else
Set Shp = Selection.ShapeRange.Item(1)
End If
If Not Shp Is Nothing Then
With Shp
.LockAspectRatio = True
' for absolute positioning
'.Left = CentimetersToPoints(5.5)
'.Top = CentimetersToPoints(0.5)
'.Width = CentimetersToPoints(2.5)
'put the image behind text
.WrapFormat.Type = wdWrapBehind
'this was the tricky part, discovering this
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Top = wdShapeTop 'if you say =0, it sets the AbsolutePx in the dialog
.Left = wdShapeRight 'these wdShapeXX objects set the Align field in the dialog
End With
End If
Set Shp = Nothing
Application.ScreenUpdating = True
End Sub
Just discovered this feature to answer my own question. See the answer in the question posting.
I have the following problem: I want to set a chart background with "Gradient Fill" and change the angle with a macro.
Recording a Macro does not help. The only thing I got is the following:
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 117, 117)
.BackColor.RGB = RGB(0, 203, 92)
.TwoColorGradient msoGradientDiagonalUp, 1
End With
In reality I want to set the colors in advance and use the macro just for orientation. The only thing the macro should do is:
If variable = A then 'select the chart and set angle to 45%
If variable = B then 'select the chart and set the angle to 135%
and so on.
I do not want to set manually the colors because I will have 4 colors and it useless to set them every time since their relative position is always the same within the gradient pattern.
Any Idea?
Ok, I made it.
It is very simple, but you cannot easily find this info online.
You need to activate your chart and after:
ActiveChart.PlotArea.Format.Fill.GradientAngle = 45
With PowerPoint 2007 & 2010, I have been trying to change the Type of Gradient Fill on a Shape object from default "Rectangular" to "Path" for days. Searched online but seems like no such question asked.
So far I can only get the Gradient Fill to be "Rectangle" (the default with 2 color gradient?). But I want it to be "Path". So far only able to do that by right click on the actual Shape --> Format Shape. "Format Shape" form shows and I can change the "Type:" from Rectangle to Path. But I want to do this change in VBA, anyone have a solution?
My code below. Variables starting with g are As Single
Set oSlide = ActivePresentation.Windows(1).View.Slide
With oSlide.Shapes.AddShape(msoShapeIsoscelesTriangle, gLeft, gTop, gWidth, gHeight)
.Line.Visible = msoFalse ' No Outline
.Adjustments(1) = gAdj1 ' Adjust the position of the pointing tip
.Rotation = gAngle ' Change the angle of Rotation
.Fill.Visible = msoTrue
.Fill.TwoColorGradient msoGradientFromCenter, 1 ' Enable Two Colour Gradient
.Fill.GradientStops(1).Color.RGB = RGB(255,255,255) ' Colour at center
.Fill.GradientStops(2).Color.RGB = RGB(121,121,121) ' Colour at edge
.Select
End With
Set oSlide = Nothing
If no VBA codes can achieve that, I will have to use workaround... Copy and Paste those Shapes from a Template file - this sounds bad as I am going to make it a PowerPoint AddIn.
Thanks in advance!
Patrick