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
Related
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...
I have written a code that charts various data. The charts are then exported as .gif files. The image files are then loaded as pictures into image controls in a userform as shown below.
How do I go about exporting the whole userform (preferably without the 3 buttons on the right) as an image for use in a report?
Currently I am using manual printscreen but it is quite time consuming..
Chart Example
Currently I am manually using printscreen but it is quite time consuming..
Is there a way to access the alt-printscreen button perhaps?
The chart creation code itself isn't really relevant but I can share if required.
I expect an image file that I can then use within a word document.
Preferably cropped to remove the 3 buttons on the right of the userform.
Steven,
In the below sub, I used the SendKeys method to send Alt+PrintScreen ("%{1068}") and Ctrl+V ("^v") on the current application. The SendKeys method simulates the key presses of a keyboard, so it would replicate what you're doing right now.
Sub PrintTheScreen()
Application.SendKeys ("%{1068}")
DoEvents
Application.SendKeys ("^v")
DoEvents
End Sub
Reference for this method can be found here
Having the sendkeys applied to the userform will simulate your button press. By then, you could set a word application object and paste the printed screen, for example.
Sub CreatingWDDoc()
Dim appWD As Word.Application
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
appWD.Documents.Add
appWD.SendKeys ("^v")
' Change the string to the path you wish to use for seving the file
appWD.SaveAs (“”)
appWD.Quit
End Sub
Keep in mind that to use such functions, you need to have the word library referenced in your project, under Tools >> References. More information can be found here.
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.
I would like to create a button to open a url that is shown in a excel cell. the url is generated by the user filling in some information so i'd like to put a button next to the end url which will take the user directly to the page they requested.
could someone please help with this question?
Thanks
Ian
You could use the solution from there Open an html page in default browser with VBA?:
Public Sub ButtonClick()
ThisWorkbook.FollowHyperlink (Range("B2").Value) 'TODO: change cell!
End Sub
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.