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:
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:
The code for the upload Userform:
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
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:
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