0

Is it possible to edit the position of the icon and text in a OLEObject?

Like this

The default layout is as shown, and i would like to make it like this.

Does anyone now if this is possible within VBA, or maybe there is an alternativ solution.

Here is my code:


Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
  (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long

Sub UploadFile()
 Dim iconToUse As String, fullFileName As String, shortFileName As String
 Dim FNExtension As String
 Dim Attachment As OLEObject
 
 'Select file and get path
 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, "."))
 
 'Get file name only
 shortFileName = Mid(fullFileName, InStrRev(fullFileName, "\") + 1)
 
 'Select icon based on filename extension
 Select Case UCase(FNExtension)
   Case Is = "DOCX"
     iconToUse = "C:\Program Files (x86)\Microsoft Office\root\Office16\WORDICON.EXE"
   Case Is = "XLS", "XLSM", "XLSX"
     iconToUse = "C:\Program Files (x86)\Microsoft Office\root\Office16\XLICONS.EXE"
   Case Is = "PDF"
     iconToUse = "C:\Windows\Installer\{AC76BA86-1033-FFFF-7760-0E1401753200}\_PDFFile.ico"
   Case Else
     iconToUse = "C:\Windows\system32\packager.dll"
 End Select
 
 'Insert til Attachment
 Set Attachment = ActiveSheet.OLEObjects.Add(Filename:=fullFileName, _
   Link:=False, DisplayAsIcon:=True, IconFileName:=iconToUse, _
   IconIndex:=0, IconLabel:=shortFileName, Top:=ActiveCell.Top, _
             Left:=ActiveCell.Left)

End Sub


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 ```
  • 1) Make your own Icons with text (in the picture) at the right and use the crop function through format object to make it a rectangle 2) add your own picture/shape which will open the embedded document (somewhere hidden) – EvR Feb 03 '22 at 16:37
  • Thank you for the idea! However, i was hoping it was possible to edit the OLEobject but it seems not. – Kenni Scheidle Feb 07 '22 at 10:26

0 Answers0