Re: Inserting Picture from File using VBA
From: Roderick O'Regan (roregan_at_businesstraining.co.uk.NOSPAM)
Date: 03/17/04
- Next message: Roderick O'Regan: "PowerPoint and .INI files"
- Previous message: Shari K: "Re: sound to a checkbox"
- In reply to: Bill Dilworth: "Re: Inserting Picture from File using VBA"
- Next in thread: John Langhans [MSFT]: "Re: Inserting Picture from File using VBA"
- Reply: John Langhans [MSFT]: "Re: Inserting Picture from File using VBA"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 17 Mar 2004 21:14:35 -0000
Thanks Bill. That was a pretty good shove! With what I already had taken
from VBA Help coupled to your suggestion and a bit of pushing and shoving
the code about I've created the following:
Sub Main()
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'Declare a variable to contain the path
Dim vrtSelectedItem As Variant
Dim FileName As String
'Use a With...End With block to reference the FileDialog object.
With fd
'Set the tile of the dialog box as well as the action button
.InitialFileName = "C:\"
.Title = "Insert Picture"
.ButtonName = "Insert"
.InitialView = msoFileDialogViewDetails
'Add a filter that includes GIF and JPEG images and make it the
first item in the list.
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg,*.png,
*.eps,*.tif,*.tiff", 1
'Use the Show method to display the File Picker dialog box and
return the user's action.
'The user pressed the action button.
If .Show = -1 Then
'Step through each string in the FileDialogSelectedItems
collection.
For Each vrtSelectedItem In .SelectedItems
'vrtSelectedItem is a String that contains the path of each
selected item.
ActiveWindow.Selection.SlideRange.Shapes.AddPicture(vrtSelectedItem,
msoFalse, msoCTrue, 206, 206).Select
Next vrtSelectedItem
'The user pressed Cancel.
Else
End If
End With
'Set the object variable to Nothing.
Set fd = Nothing
End Sub
Works a treat!
"Bill Dilworth" <vestprog2@yahoo.org> wrote in message
news:eo%238dJ%23CEHA.3584@TK2MSFTNGP11.phx.gbl...
> This is quick and ugly, but you only wanted nudged in the right direction,
> not taken there, right?
>
> Sub Macro1()
>
> ActiveWindow.Selection.SlideRange _
> Shapes.AddPicture(FileName:= _
> "C:\My Documents\My Pictures\Picture.jpg", _
> LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, _
> Left:=206, Top:=73, Width:=309, Height:=395).Select
>
> End Sub
>
>
> This will, when run in edit mode, add the picture "Picture.jpg" to your
> slide.
> --
> Bill Dilworth, Microsoft PPT MVP
> ===============
> Please spend a few minutes checking vestprog2@
> out www.pptfaq.com This link will yahoo.
> answer most of our questions, before com
> you think to ask them.
>
> Change org to com to defuse anti-spam,
> ant-virus, anti-nuisance misdirection.
> .
> .
>
> "Roderick O'Regan" <roregan@businesstraining.co.uk.NOSPAM> wrote in
message
> news:uJHss16CEHA.3568@tk2msftngp13.phx.gbl...
> > I am able to write the appropriate code to insert a graph in the
> > presentation slide but seem unable to follow the same principles when
> > attempting to write code that will do what I can achieve manually i.e.
the
> > VBA equivalent of Insert|Picture|From File... followed by the Insert
> Picture
> > dialog opening.
> >
> > Could someone nudge me in the right direction, please?
> >
> > Regards
> >
> > Roderick O'Regan
> >
> >
>
>
- Next message: Roderick O'Regan: "PowerPoint and .INI files"
- Previous message: Shari K: "Re: sound to a checkbox"
- In reply to: Bill Dilworth: "Re: Inserting Picture from File using VBA"
- Next in thread: John Langhans [MSFT]: "Re: Inserting Picture from File using VBA"
- Reply: John Langhans [MSFT]: "Re: Inserting Picture from File using VBA"
- Messages sorted by: [ date ] [ thread ]