Hi Everyone,
I have a code to upload an object into excel. However below code i am able to upload only one document by clicking on button. Please help me in amend the code by which i can upload multiple file.
note - other file path would remain same. However name could be sample2.pdf or sample3.pdf
Sub Button21_Click()
Dim strPath As String
Dim strFilename As String
Dim strCaption As String
Dim wksTarget As Worksheet
Dim rngTarget As Range
Set wksTarget = Worksheets("Sheet1")
Set rngTarget = wksTarget.Range("A3") 'change the location in which to insert your object as desired
strPath = wksTarget.Range("A1").Value
If Right(strPath, 1) <> "" Then
strPath = strPath & ""
End If
strFilename = "sample.pdf"
If Len(Dir(strPath & strFilename, vbNormal)) = 0 Then
MsgBox "'" & strPath & strFilename & "' does not exist!", vbExclamation, "Path and/or file?"
Exit Sub
End If
strCaption = "myCaption" 'change the caption as desired
wksTarget.OLEObjects.Add _
Filename:=strPath & strFilename, _
link:=False, _
displayasicon:=True, _
iconfilename:="", _
iconindex:=0, _
iconlabel:=strCaption, _
Left:=rngTarget.Left, _
Top:=rngTarget.Top, _
Width:=150, _
Height:=10
End Sub
I have a code to upload an object into excel. However below code i am able to upload only one document by clicking on button. Please help me in amend the code by which i can upload multiple file.
note - other file path would remain same. However name could be sample2.pdf or sample3.pdf
Sub Button21_Click()
Dim strPath As String
Dim strFilename As String
Dim strCaption As String
Dim wksTarget As Worksheet
Dim rngTarget As Range
Set wksTarget = Worksheets("Sheet1")
Set rngTarget = wksTarget.Range("A3") 'change the location in which to insert your object as desired
strPath = wksTarget.Range("A1").Value
If Right(strPath, 1) <> "" Then
strPath = strPath & ""
End If
strFilename = "sample.pdf"
If Len(Dir(strPath & strFilename, vbNormal)) = 0 Then
MsgBox "'" & strPath & strFilename & "' does not exist!", vbExclamation, "Path and/or file?"
Exit Sub
End If
strCaption = "myCaption" 'change the caption as desired
wksTarget.OLEObjects.Add _
Filename:=strPath & strFilename, _
link:=False, _
displayasicon:=True, _
iconfilename:="", _
iconindex:=0, _
iconlabel:=strCaption, _
Left:=rngTarget.Left, _
Top:=rngTarget.Top, _
Width:=150, _
Height:=10
End Sub