VBA Shape.Fill.UserPicture doesn't load the picture - vba

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"

Related

change the color and thickness of the font border of a powerpoint wordart from vba

How can I change the color and thickness of the font border of a powerpoint wordart from vba? I'm trying with .TextFrame.TextRange but I can't find the way
I have an old web page that generates a powerpoint file and I want to modify the border of the letter of the texts in wordart that it contains
Lots of things that you can do in Powerpoint, you can do also in Excel (eg Wordart). So if you have Excel (or Word), do the actions you want to do there and record a Macro to get an idea about the properties you need to change.
Setting the character formatting for text can be done via TextFrame2.Characters. In your case, change properties of Font.Line.
Dim slide As slide
For Each slide In ActivePresentation.Slides
Dim sh As Shape
For Each sh In slide.Shapes
If sh.HasTextFrame Then
With sh.TextFrame2.TextRange.Characters.Font.Line
If .Visible Then ' Prevent changing "normal" text
' Adapt the following lines to your need
.ForeColor.ObjectThemeColor = msoThemeColorAccent2
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.25
.Weight = 1
.Transparency = 0
End If
End With
End If
Next
Next

VBA Word Macro selecting inserted shape

I wish a simple VBA macro that inserts a picture then changes its height and width. It works first time run. The user, however, can add multiple pictures by running the macro more than once and my problem is that the macro inserts the next image but then resizes an image already on the document rather than the one just inserted. I would have assumed that the .count would return the last image (i.e. the one jsut inserted) It appears that the 'Set myImage line' doesn't reference the just inserted image.
Any help welcome. Code below.
Greg
ActiveDocument.Shapes.AddPicture Anchor:=Selection.Range, FileName:= _
"c:\mydir\carp3d.tif", LinkToFile:=False, SaveWithDocument:=True
' get last inserted image
Set myImage = ActiveDocument.Shapes(ActiveDocument.Shapes.Count)
myImage.Select
myImage.LockAspectRatio = msoTrue
myImage.LockAspectRatio = msoTrue
myImage.Height = 180#
myImage.Width = 124.55
Shapes.AddPicture returns a Shape object that you should capture:
Set myImage = ActiveDocument.Shapes.AddPicture(....)
myImage.LockAspectRatio = msoTrue
' and so on

Changing Font Outline color inside a Table Cell with VBA using Application.CommandBar.ExecuteMSO

Win10x64 Office 365 PPT v 16.0.12325.202080 64-bits
I need to show a character with a yellow font color but a black outline, for readability purposes. This character goes inside a Powerpoint table Cell.
The following link has a method that I'm currently using that consists of creating a dummy shape, adding text to it, modify the shape's textframe2 textrange font line properties and then copying it and pasting it back to the table cell.
http://www.vbaexpress.com/forum/archive/index.php/t-43787.html
This was asked 8 years ago, but I'm currently seeing the same behaviour where we can't directly manipulate the textframe2 wordart format of text inside a cell. The program doesn't show an error but doesn't work.
I have given up on trying to modify the textrame2 textrange font line properties directly from VBA.
I have managed to get it to activate the font outline color using
Application.CommandBars.ExecuteMso ("TextOutlineColorPicker")
After it's activated I thought I could modify the textframe2 textrange font line properties, but it still doesn't work.
Is there an Application.CommandBars idMso for changing the font outline color and font outline line width inside a table cell?
Or another other than pasting the formatted text inside a table cell.
Edit:
Adding an image to illustrate what I mean by text color and text outline color and the menu used to show them in red circle:
Edit2
Added another snapshot to exemplify a character inside a cell with black outline and a character inside a cell without an outline
Thanks
Here's an example to access a Table on a given slide and change one cell's attributes. The example slide I'm using looks like this
The code itself creates a function that allows you to select a table from a particular slide, and a single cell within the table and highlight it.
Option Explicit
Sub test()
HighlightTableCell 1, 2, 3
End Sub
Sub HighlightTableCell(ByVal slideNumber As Long, _
ByVal thisRow As Long, _
ByVal thisCol As Long)
Dim theSlide As Slide
Set theSlide = ActivePresentation.Slides(slideNumber)
Dim shp As Shape
For Each shp In theSlide.Shapes
If shp.Type = msoTable Then
Dim theTable As Table
Set theTable = shp.Table
With theTable.Cell(thisRow, thisCol)
With .Shape.TextFrame2.TextRange.Characters.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 255, 0)
.Transparency = 0
.Solid
End With
With .Shape.TextFrame2.TextRange.Characters.Font.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
End With
End With
End If
Next shp
End Sub
This question should be answered by Microsoft Office developers.
Currently, to overcome this bug-some situation, I think, copying the formatted text outside the table and pasting it into a table cell is the only work-around for this trouble.
As you mentioned, according to John Wilson, one of the most brilliant PowerPoint MVPs(http://www.vbaexpress.com/forum/archive/index.php/t-43787.html), if we copy the text from a textbox or shape that is located outside of the table, the format of the text can be preserved even for the text in a table cell.
Option Explicit
Sub test()
Dim shp As Shape, tshp As Shape
Dim sld As Slide
Dim tbl As Table
Dim r%, c%
If ActiveWindow.Selection.Type = ppSelectionNone Then MsgBox "Select a table first.": Exit Sub
Set shp = ActiveWindow.Selection.ShapeRange(1)
Set sld = shp.Parent
'add a temporary textbox for copying the formatted text into a cell
Set tshp = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 541, 960, 540)
tshp.Visible = False
Set tbl = shp.Table
For r = 1 To tbl.Rows.Count
For c = 1 To tbl.Columns.Count
'1) cell -> 'tshp'
tbl.Cell(r, c).Shape.TextFrame2.TextRange.Copy
tshp.TextFrame2.TextRange.Paste
'2) outline the text in 'tshp'
With tshp.TextFrame2.TextRange.Font.Line
.Visible = msoTrue
.Weight = 0.2
.ForeColor.RGB = RGB(255, 127, 127)
End With
'3) 'tshp' -> cell
tshp.TextFrame2.TextRange.Copy
tbl.Cell(r, c).Shape.TextFrame2.TextRange.Paste
'// the code below doesn't work
'With tbl.Cell(r, c).shape.TextFrame2.TextRange.Characters.Font.Line
'With tbl.Cell(r, c).shape.TextFrame2.TextRange.Font.Line
' .Visible = msoTrue
' .Weight = 0.5
' .ForeColor.RGB = RGB(255, 127, 127)
'End With
Next c
Next r
'remove the tempoarary textbox
tshp.Delete
End Sub
The above snippet creates a temporary textbox on left-top area of the slide and applies the outlined text format. Then, it copies the content of each cell to the temporary textbox and copy/paste the formatted text back to the cell. By using this method, we can apply the outlined text format to the text in a cell.

Macro Excel won't past exact image to Powerpoint Presentation

The strangest thing is happening with my macro in Excel. It works like a charm, but when it has to copy 2 charts and paste into my powerpoint presentation, suddenly, the Chart isn't exactly the same.
My code:
Set Wb = Workbooks.Open("Path\WbName.xlsx", ReadOnly:=True, UpdateLinks:=0)
It opens 5 more workbooks... And then it goes through a loop, to copy all the Charts
Dim Charts_Arr As Variant
Charts_Arr = Worksheets("Parameters").ListObjects("Parameters").DataBodyRange.Value
For i = LBound(Charts_Arr) To UBound(Charts_Arr)
SourcePath = Charts_Arr(i, 8)
SheetName = Charts_Arr(i, 4)
ShapeNr = Charts_Arr(i, 2)
SlideNr = Charts_Arr(i, 3)
Schaling = Charts_Arr(i, 6)
Set Source = Workbooks(SourcePath)
Set PPpres = oPPTApp.ActivePresentation
Set Sh = Source.Sheets(SheetName).Shapes(ShapeNr)
Sh.Copy
Set NewSh = PPpres.Slides(SlideNr).Shapes.PasteSpecial(ppPasteJPG)
With NewSh
.Top = Charts_Arr(i, 5)
.Left = Charts_Arr(i, 7)
.ScaleHeight Schaling, msoTrue
End With
Next i
This goes perfectly. But when I take a look at the ppt-file, 2 charts are not exactly the same.
(TIP: Excel is Chartarea, not a shape - didn't know this at first)
When copy the picture manually, I get the correct picture:
And what's more bizarre, I have 2 other Charts on another Sheet in the same workbook who doesn't cause any problems.
Could this be a problem with links, or the way I copy?
UPDATE
If I adjust the code as suggested below:
Source.Sheets(SheetName).ChartObjects(ShapeNr).Chart.CopyPicture
Set NewSh = PPpres.Slides(SlideNr).Shapes.Paste
With NewSh
.Top = Charts_Arr(i, 5)
.Left = Charts_Arr(i, 7)
.ScaleHeight Schaling, msoTrue
End With
I get this:
I'm doing something wrong with the Paste part of the code, I guess.
Tried other possibilities, always end up getting no images, or the one above.
FIXERSUPDATE
So I made/used a loophole. Couldn't find a way to paste the images directly into Powerpoint, So I pasted it into an excelsheet 'Temp' instead. And adjusted the Array, and that seemed to work. But I still would like to know how to do this directly in Powerpoint.
Thanks in advance for your insights!
I couldn't find a PasteSpecial Option that could fix the issue.
CopyasPicture works, but I can't seem to figure out how to paste it directly into ppt. So I used a workaround. I created a 'Temp' Sheet, where I could paste the Chart as Picture in the right format, afterwards I could program it to paste the shape into Ppt. Not the cleanest way to solve the issue, but it works.

VB.NET MS PowerPoint Slide Background

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.