Inserting a picture option

styler

Board Regular
Joined
May 22, 2003
Messages
77
I cant seem to find any help on how to set up a button that when you press it a browse box will pop up, allow the user to select a picture and insert it onto a blank worksheet at the end of a document.

Can anyone help me with this or is it impossible.

Cheers
Si
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi there,

Try the following (paste it into the code for your button). Its very basic, opens up the Open dialog box (limiting you to JPG and BMP files, and inserts what ever file you choose into Sheet2. The picture is currently set to be inserted at the top left of sheet 2, you can change this by selecting a different cell before inserting the image. (change the ActiveSheet.Cells(1, 1).Select line)


Code:
Dim filetoopen As String
filetoopen = Application.GetOpenFilename("Picture Files (*.jpg;*.bmp), *.jpg;*.bmp")
If filetoopen <> "False" Then
    Sheets("Sheet2").Activate
    ActiveSheet.Cells(1, 1).Select
    ActiveSheet.Pictures.Insert(filetoopen).Select
End If

Hope this helps

Richard
 
Upvote 0
That works well, thanks. Is there a way I can tweak the code to generate a worksheet automatically and insert the picture in there? or is that too much.

Regards
Si
 
Upvote 0
Hi,

Try the following, it will add a worksheet and put your picture in it.

Code:
Dim filetoopen As String
Dim sheetno As Integer
sheetno = ActiveWorkbook.Sheets.Count
filetoopen = Application.GetOpenFilename("Picture Files (*.jpg;*.bmp), *.jpg;*.bmp")
If filetoopen <> "False" Then
    Worksheets.Add after:=Sheets(sheetno)
    ActiveSheet.Cells(1, 1).Select
    ActiveSheet.Pictures.Insert(filetoopen).Select
End If

Hope this helps

Richard
 
Upvote 0

Forum statistics

Threads
1,203,326
Messages
6,054,743
Members
444,748
Latest member
knowak87

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top