In VBA, I am embedding a file.
According to the file extension, I want to assign an image to the file. I am trying to alter the code found here Link:--> MrExcel - Attaching/ Embedding Files Using VBA
The change I want to make is to use one of the 4 images that I have on the admin sheet of the workbook.
I have tried a couple different methods but cannot get it to work.
Here is my latest try. Any assistance is greatly appreciated.
-Pujo
And the Function
According to the file extension, I want to assign an image to the file. I am trying to alter the code found here Link:--> MrExcel - Attaching/ Embedding Files Using VBA
The change I want to make is to use one of the 4 images that I have on the admin sheet of the workbook.
I have tried a couple different methods but cannot get it to work.
Here is my latest try. Any assistance is greatly appreciated.
-Pujo
VBA Code:
'https://www.mrexcel.com/forum/excel-questions/1020429-attaching-embedding-files-using-vba.html
Sub Insert()
Dim iconToUse As String, fullFileName As String
Dim FNExtension As String
Dim o As OLEObject
fullFileName = Application.GetOpenFilename("*.*, All Files", , , , False)
If fullFileName = "False" Then Exit Sub ' user cancelled
'choose an icon based on filename extension
'get all after last "." in filename
FNExtension = Right(fullFileName, Len(fullFileName) - _
InStrRev(fullFileName, "."))
'select icon based on filename extension
Select Case UCase(FNExtension)
Case Is = "TXT" 'NotePad
iconToUse = Sheet7.Shapes("NoteIcon")
Case Is = "XLS", "XLSM", "XLSX" 'Excel
iconToUse = Sheet7.Shapes("ExcelIcon")
Case Is = "DOC", "DOCX", "DOT" 'Excel
iconToUse = Sheet7.Shapes("WordIcon")
Case Is = "PDF" 'Acrobat PDF
iconToUse = Worksheets("Admin").Shapes("PdfIcon")
Case Else
'this is a generic icon
iconToUse = Sheet7.Shapes("GenericIcon")
End Select
End Sub
And the Function
VBA Code:
Function ExePath(lpFile As String) As String
Dim lpDirectory As String, sExePath As String, rc As Long
lpDirectory = "\"
sExePath = Space(255)
rc = FindExecutable(lpFile, lpDirectory, sExePath)
sExePath = Left$(sExePath, InStr(sExePath, Chr$(0)) - 1)
ExePath = sExePath
End Function