Home |
Search |
Today's Posts |
|
#1
|
|||
|
|||
VBA Script to insert image
Hi there,
I am struggling on getting a VBA script to work correctly for a spreadsheet and I am seeking guidance. I am using Excell 2007 Professional and what I am trying to do is create a profile pages for an event at work. What i'm trying to do is have the profile page set up, and where the picture will go have a box the user can click, once they click the box it will load a window for them to browse their computers directory to find the image, choose the image and say "ok" and it will insert and resize the image to the specified cell size. Once the image is inserted the box would either be covered up or disapear. Can this be achieved? All I have been able to figure out is the following which will not resize or set destination cell and only allows JPEG's. Please help! I am new to trying to code VBA projects. Private Sub CommandButton1_Click() Dim JPeg() Dim flname As Variant flname = Application.GetOpenFilename If flname < False Then If Right(flname, 3) = "jpg" Then ActiveSheet.Pictures.Insert (flname) Else MsgBox "That is not a jpeg file" End If End If End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA Script to insert image
hi,
Private Sub CommandButton1_Click() Dim fd As FileDialog Dim ffs As FileDialogFilters Dim Rng As Range Set Rng = ActiveSheet.Range("B8") ' adapt to your range Rng.Select Set fd = Application.FileDialog(msoFileDialogOpen) With fd Set ffs = .Filters With ffs .Clear .Add "Pictures", "*.jpg" End With .AllowMultiSelect = False If .Show = False Then Exit Sub Fichier = fd.SelectedItems(1) Set Pict = ActiveSheet.Pictures.Insert(Fichier) Pict.ShapeRange.LockAspectRatio = msoFalse Pict.Height = Rng.Height Pict.Width = Rng.Width End With End Sub isabelle Le 2014-07-18 11:06, clvrbas a écrit : Hi there, I am struggling on getting a VBA script to work correctly for a spreadsheet and I am seeking guidance. I am using Excell 2007 Professional and what I am trying to do is create a profile pages for an event at work. What i'm trying to do is have the profile page set up, and where the picture will go have a box the user can click, once they click the box it will load a window for them to browse their computers directory to find the image, choose the image and say "ok" and it will insert and resize the image to the specified cell size. Once the image is inserted the box would either be covered up or disapear. Can this be achieved? All I have been able to figure out is the following which will not resize or set destination cell and only allows JPEG's. Please help! I am new to trying to code VBA projects. Private Sub CommandButton1_Click() Dim JPeg() Dim flname As Variant flname = Application.GetOpenFilename If flname < False Then If Right(flname, 3) = "jpg" Then ActiveSheet.Pictures.Insert (flname) Else MsgBox "That is not a jpeg file" End If End If End Sub |
#3
|
|||
|
|||
This works really great, one problem though; when I protect the sheet it re sizes to normal size and has an error, is there a way around that?
Quote:
|
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA Script to insert image
hi,
when you protect the sheet, you have to allow the users to edit objects (DrawingObjects:=False) ActiveSheet.Protect "password", DrawingObjects:=False, Contents:=True, Scenarios:=True isabelle Le 2014-07-21 11:58, clvrbas a écrit : This works really great, one problem though; when I protect the sheet it re sizes to normal size and has an error, is there a way around that? |
#5
|
|||
|
|||
Quote:
-- Chris |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA Script to insert image
hi,
Private Sub CommandButton1_Click() Dim fd As FileDialog Dim ffs As FileDialogFilters Dim Rng As Range ActiveSheet.UnProtect "password" Set Rng = ActiveSheet.Range("B8") ' adapt to your range Rng.Select Set fd = Application.FileDialog(msoFileDialogOpen) With fd Set ffs = .Filters With ffs .Clear .Add "Pictures", "*.jpg" End With .AllowMultiSelect = False If .Show = False Then Exit Sub Fichier = fd.SelectedItems(1) Set Pict = ActiveSheet.Pictures.Insert(Fichier) Pict.ShapeRange.LockAspectRatio = msoFalse Pict.Height = Rng.Height Pict.Width = Rng.Width End With ActiveSheet.Protect "password", DrawingObjects:=True, Contents:=True, Scenarios:=True End Sub isabelle Le 2014-07-21 16:56, clvrbas a écrit : isabelle;1618222 Wrote: hi, when you protect the sheet, you have to allow the users to edit objects (DrawingObjects:=False) isabelle Le 2014-07-21 11:58, clvrbas a écrit :- This works really great, one problem though; when I protect the sheet it re sizes to normal size and has an error, is there a way around that? - Thank you, i should have specified more clearly. I was hoping I could only allow users to edit that particular object, and not the other objects I have on the sheet. I'll insert this and see what I can do! :) Thank you for your help. -- Chris |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Script to insert Row | Excel Discussion (Misc queries) | |||
Need VBA script to auto-insert value upon row insert | Excel Worksheet Functions | |||
Insert image, get name of image | Excel Programming | |||
Insert a key function in VBA script | Excel Programming | |||
insert excel vb script | Excel Programming |