I've developed a small ticketing system on excel VBA The Save button will take all data from textboxes and radio button and add it to the row number 7 (in this case) But when I press upload I can't add the link to the label of attachments
How to add link to the attachment label using (upload file ) button And also save the Link value stored in upload file button to use it later in clear button and save button?
I'm confused to work with private sub and private dim variables. I'm newbie in VBA please help
The Upload button
Public Sub btnAttachment_Click()
'To upload file link format is png, jpeg, PDF or All files'
Dim wks As Worksheet
Dim LinksList As Range
Dim lastRowLink As Long
Dim LinkAttached As Long
Set wks = ActiveSheet
Set LinksList = Range("N1")
'declare last row to insert link to
lastRowLink = WorksheetFunction.CountA(Sheets("Tickets").Range("A:A"))
Sheets("Tickets").Cells(lastRow + 1, 11).Value = LinkAttached
ChDrive "C:\"
ChDir "C:\"
Filt = "PNG Files(*.png),*.png ," & _
"Jpeg Files(*.jpeg),*.jpg ," & _
"PDF Files (*.pdf),*.pdf ," & _
"All Files (*.*),*.*"
FilterIndex = 1
Title = "Select a File to Hyperlink"
Filename = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Title)
If Filename <> False Then
wks.Hyperlinks.Add Anchor:=LinksList, _
Address:=Filename, _
TextToDisplay:=Filename
Else
MsgBox "No file was selected.", vbCritical, "Loading Error"
Exit Sub
End If
End Sub
The Save button code
Public Sub BtnSave_Click()
Dim Ws As Worksheet
Dim lastRow As Long
Dim openOn As Date
'Declare openBy to date Now function'
openOn = Now()
'set format function on time var'
openTimeAmPM = Format(openOn, "m.d.yy h:mm AM/PM")
'if no all information required inserted, show error'
If SieraForum.txtTicketName.Value = "" Or (SieraForum.ErrorOption = False And SieraForum.OrderOption = False) Or SieraForum.CombLocation.Value = "" Or SieraForum.CombOpenBy.Value = "" Or SieraForum.CombTicketStatus.Value = "" Then
MsgBox " Please fill All information required (Ticket Name, Severity, Location, OpenBy)"
Else
lastRow = WorksheetFunction.CountA(Sheets("Tickets").Range("A:A"))
Sheets("Tickets").Cells(lastRow + 1, 1).Value = lastRow
Sheets("Tickets").Cells(lastRow + 1, 2).Value = SieraForum.txtTicketName.Value
If SieraForum.ErrorOption = True Then
Sheets("Tickets").Cells(lastRow + 1, 3).Value = "Error"
Else
Sheets("Tickets").Cells(lastRow + 1, 3).Value = "Order"
End If
Sheets("Tickets").Cells(lastRow + 1, 4).Value = SieraForum.CombSeverity.Value
Sheets("Tickets").Cells(lastRow + 1, 5).Value = SieraForum.CombLocation.Value
Sheets("Tickets").Cells(lastRow + 1, 6).Value = SieraForum.txtTicketDetails.Value
Sheets("Tickets").Cells(lastRow + 1, 7).Value = SieraForum.CombOpenBy.Value
Sheets("Tickets").Cells(lastRow + 1, 8).Value = SieraForum.CombCloseBy.Value
Sheets("Tickets").Cells(lastRow + 1, 9).Value = SieraForum.CombTicketStatus.Value
Sheets("Tickets").Cells(lastRow + 1, 10).Value = openTimeAmPM
'Sheets("Tickets").Cells(lastRow + 1, 13).Value =
'Display new ticket number on the label'
lbTicketNumVal.Caption = lastRow
End If
'to clear data after pressing Save button'
'Clear the data from the form'
SieraForum.txtTicketName.Value = ""
SieraForum.ErrorOption = False
SieraForum.OrderOption = False
SieraForum.CombSeverity = ""
SieraForum.CombLocation = ""
SieraForum.txtTicketDetails = ""
SieraForum.CombOpenBy = ""
SieraForum.CombCloseBy = ""
SieraForum.CombTicketStatus = ""
lbTicketNumVal.Caption = lastRow + 1
'to save excel sheet editing'
ActiveWorkbook.Save
End Sub