Uploading an actual image, not just its path, with Userforms

tinytwo

New Member
Joined
Dec 8, 2015
Messages
1
Hi all,

I'm currently working on an issue ticketing system, but have been struggling with attaching images. I am using a Userform for people to upload their images to provide context for their log entry, but right now the image's path is posted in the cell, instead of the actual picture being placed on the sheet. The file path displays the image correctly as a picture on the User 1's computer, but User 2 doesn't have that same path on their computer, so it obviously does not display.

Here is the Upload section of the Userform:

H86s5MS.jpg


The image is placed on the second tab called Screenshots. Again, I am looking for a way to redo my code and have the actual picture be uploaded and placed on the sheet, instead of the path.

This is the code for the upload module:
Code:
Sub insert_pic(sFilePath As String)
    Dim s            As String
    Dim LastRow      As Long
    Dim LastColumn   As Long
    Dim TicketNum    As String

s = sFilePath

'Finds and Selects the last filled row
LastRow = Sheets("Screenshots").Range("A" & Rows.Count).End(xlUp).Row

'Finds and Selects the last filled coulmn
LastColumn = Sheets("Screenshots").Cells(1, Columns.Count).End(xlToLeft).Column

'Finds the matching ticket number from the issue
TicketNum = ufUploadAgain.txtTicketNum.Text

    With Sheets("Screenshots").Pictures.Insert(sFilePath)
    With .ShapeRange
        .LockAspectRatio = msoTrue
        .Width = 150
        .Height = 200
    End With
    
    If Sheets("Screenshots").Cells(LastRow + 1, 2).Value = "" Then
        Sheets("Screenshots").Rows(LastRow + 1).RowHeight = 250
        Sheets("Screenshots").Cells(LastRow + 1, 1).Value = TicketNum
        .Left = Sheets("Screenshots").Cells(LastRow + 1, LastColumn + 1).Left
        .Top = Sheets("Screenshots").Cells(LastRow + 1, LastColumn + 1).Top
        .Placement = 1
        .PrintObject = True
    End If
    End With

End Sub

The code for the upload Userform:
Code:
Sub cmdUpload_Click()
Dim fileToOpen   As Variant

'Checks to see if Ticket Number is filled out. Displays an error message if it is empty.
If txtTicketNum.Value = "" Then
    MsgBox "Please enter your Ticket Number."
'Checks to see if Ticket Number is filled out. Starts upload if it is filled.
ElseIf txtTicketNum.Value <> "" Then
    fileToOpen = Application _
        .GetOpenFilename("All Picture Files (*.jpg;*.gif;*.bmp;*.tif),*.jpg;*.gif;*.bmp;*.tif")
End If

On Error GoTo ErrorHandler
    If fileToOpen <> False Then
        'Displays a preview in the frame
        Me.frmPhoto.Picture = LoadPicture(fileToOpen)
        'Displays the path in the text box
        txtFile = fileToOpen
        'Runs the module that inserts images
        UploadAgain.insert_pic (fileToOpen)
    End If
Exit Sub

'If there is an error with the above code, this error message will pop up
ErrorHandler:
    MsgBox "Hmm... There's something wrong with this photo." & vbNewLine & vbNewLine & "Please again try with another image."
    
End Sub

TL;DR - Need to scrap the code that uploads the image's path to the excel sheet, and instead upload the actual image and place that on the sheet instead.

Thank you,
tiny
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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