I have an excel file with several toggle buttons. When a toggle button is on and the "calculate" command button is pressed, my activeX image frame changes. However, I have all these files in the same directory so I'd have to send the file to my employees zipped. Is there anyway to like maybe load them into the excel workbook on a hidden sheet?
Thank you
I think the LoadPicture() function will look for a system file so you don't want that.
Add the pictures into images on a worksheet. This way they will be in the workbook.
Then right click the image you just added and select properties. Select picture property and navigate to your image file.
You can change the name to make sense of your pictures also. So they don't have to be Image1 Image2 etc.
Then in your code set the picture that you want to change = the image that you want.
If something
Image1.Picture = Image2.Picture
Else
Image1.Picture = Image3.Picture
End If
Here Image1 is the picture that changes based on what happens when the calculate button is pressed. Image3 is one of the images that you loaded into the workbook.
If you are going to store them on some other worksheet you may need to declare a worksheet object and set it to that sheet
Dim ws As Excel.Worksheet
Set ws = ActiveWorkbook.Sheets("ImageWorksheet")
Image1.Picture = ws.Image3.Picture
or something like this may work.
ActiveWorkbook.Sheets("ImageWorksheet").Image3.Picture
Something like that.
Related
I am looking to have one image control with a default image set on my worksheet1. On all other worksheets I will have numerous other image controls where people can upload photos. I have a button to delete the photo they would upload but want the default image to show up when clicked. I have the code that's posted below, but its set to load from outside the file.
Private Sub CommandButton1_Click()
Image1.Picture = LoadPicture("C:\Users\jjvernon\Desktop\Upload.jpg")
End Sub
I am hoping all it will take will be to change what's in-between the parentheses.
Thank you,
JJ
Please, can someone help me!
I have a userform which is called Configurator or "Config", which has some Image-Controls.
These images together look like a door, because the userform is a configurator for doors.
(where you can change width, height, material etc...)
Mostly the "door" consists of 4 different images which make the doorframe.
Now i want to use these images on my excel-worksheet, so the user sees a picture of the door on
the worksheet too.
Which method is the best way?
I tried to copy & paste the images from userform to a excel worksheet, but i dont know how.
I hope someone of you can show me the right way to do this!
Another way could be to somehow make a screenshot of a specific area of the userform
and paste the image to the worksheet. I dont know if there is a way to do this?
Thanks for any help!
Please, try the next way:
Let us say that pictDoor1 is the name of the picture you need to 'copy' and a new button to copy it (copyPicture). Copy next code in its Click event:
Private Sub copyPicture_Click()
Dim shPict As MSForms.Image, pic As MSForms.Image
Set pic = Me.pictDoor1 'use here the real name of the Image control
Set shPict = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Image.1", link:=False, _
DisplayAsIcon:=False, left:=20, top:=20, width:=pic.width, height:=pic.height).Object
shPict.Picture = pic.Picture
End Sub
It will insert an Image control (as the picture to be copied dimensions, cut you can change them by multiplying, if need bigger ones) and place on it the necessary picture.
Then, use the newly created shape top and left according to the previously created width and height to appropriately position them...
To avoid having to store images in the workbook itself, or to first load the image into the workbook and then reference those images from a userform, is there a way to set the image value from a userform image control to a specific filepath?
Something like:
image_server.show
set image_server.image_control_name = "C:\Users\user_name\Desktop\images\island.jpg"
Apparently it's simply:
image_server.Picture = LoadPicture(filepath)
I'm working on automating a process with powershell for someone that is currently using an Excel sheet that utilizes macros and form control objects. I have the process mostly automated so far, but the sheet has a spot where the user has to click a button on the sheet which brings up a folder selection window where they select a folder for output files. The selection gets stored to a form control label object rather than in a cell. A macro then runs using the value stored in that label. I have been unable to track down any information on how I can modify the value for that label object through powershell.
Here is the VBA code that assigns the value to the label:
Private Sub SelectFolderButton_Click()
'Selects the folder (directory) for output files
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
If (-1 = .Show) Then FolderLabel.Caption = .SelectedItems(1)
End With
End Sub
Unfortunately the user doesn't want the vba code to be changed. So I can't modify it to store the value in a cell and then have the macro use the cell instead, which would make this a lot easier.
If $wB would be the workbook object and the label "lblTest" is a Form Control shape of the worksheet "testSheet" you can try this in order to obtain the label value:
$wB.Worksheets.item("testSheet").Shapes.item("lblTest").Oleformat.Object.Object.Caption
I am trying to link and insert a picture (*.png) into a shapes fill in powerpoint using vba in Excel. In the end I will loop through this on 100+ pages and the pictures will be updated frequently so automating this will be a huge time saver. Currently I have figured out how to loop through the pages and insert the pictures into the shapes, but I have been unable to figure out how to link the pictures too.
I'm using the below code to fill the shape with the picture but I can't find the syntax to both insert and link it:
Pres.Slides(1).Shapes(ShapeName).Fill.UserPicture PictureFilePath
Ultimately this should behave like clicking on a shape, going format > shape fill > picture > insert and link (On the drop down next to insert in the dialog box).
Not all user interface actions are in the VBA object model. One of those exceptions is creating a link to a shape fill. The closest you can get is to link pictures that are inserted as pictures rather than as fills. Here's the syntax to add a linked picture. It assumes the picture is in the same folder as the presentation:
Sub Macro1()
ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="Picture1.png", LinkToFile:=msoTrue, SaveWithDocument:=msoFalse, Left:=300, Top:=251, Width:=121, Height:=38).Select
End Sub
Welcome to SO.
For answering your question, I'll give some credit to this similar SO question based on Excel and this similar SO question based on PP. Some additional information was gathered from the microsoft documentation on the subject.
What you seem to be looking for is the ActionSetting object in the shapes class, which seems to be availible to shapes in PowerPoint. Below is a code snippet created directly in PowerPoint VBA
Sub insertPictureIntoShapeWithLinkToPicture()
Dim PP_Slide As Slide, PP_Shape As Shape, imagePath As String
Set PP_Slide = ActivePresentation.Slides(1) 'Set slide (change as necessary)
Set PP_Shape = PP_Slide.Shapes(1) 'Set shape (change as necessary)
imagePath = "Path to image"
With PP_Shape
'add picutre
.Fill.UserPicture imagePath
'Set an action on click
With .ActionSettings(ppMouseClick)
'Set action to hyperlink
.Action = ppActionHyperlink
'Specify address
.Hyperlink.Address = imagePath
End With
End With
End Sub
The same approach should be available via Excel, either adding a reference to the PowerPoint object library, or using Late-Binding methods. Note that the 'click' method with hyperlink defaults to standard hyperlink clicking (ctrl + left mouse for windows with a Danish keyboard).
Please find attached code.
First create a shape in PPT and run the code.