Home

Generic check mark for files inserted through VBA

%3CLINGO-SUB%20id%3D%22lingo-sub-557938%22%20slang%3D%22en-US%22%3EGeneric%20check%20mark%20for%20files%20inserted%20through%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-557938%22%20slang%3D%22en-US%22%3E%3CP%3EDear%20all%26nbsp%3B%3CBR%20%2F%3EI've%20created%20an%20'attach%20file'-button%20in%20my%20spreadsheet%20using%20the%20below%20macro.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20however%20like%20for%20the%20icon%20of%20the%20attached%20file%20to%20be%20a%20generic%20green%20check%20mark%20instead%20of%20the%20excel.exe%20icon...%3CBR%20%2F%3E%3CBR%20%2F%3ECan%20anyone%20help%20me%20modify%20the%20below%20macro%20to%20do%20that%3F%3CBR%20%2F%3E%3CBR%20%2F%3EBr.%3C%2FP%3E%3CP%3ERobusfar%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EMy%20macro%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPublic%20Sub%20insertFile()%3CBR%20%2F%3E%3CBR%20%2F%3E'Select%20the%20cell%20in%20which%20you%20want%20to%20place%20the%20attachment%3CBR%20%2F%3ERange(%22F11%22).Select%3CBR%20%2F%3E%3CBR%20%2F%3E'Get%20file%20path%3CBR%20%2F%3Efpath%20%3D%20Application.GetOpenFilename(%22All%20Files%2C*.*%22%2C%20Title%3A%3D%22Select%20file%22)%3CBR%20%2F%3EIf%20LCase(fpath)%20%3D%20%22false%22%20Then%20Exit%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3E'Insert%20file%3CBR%20%2F%3EActiveSheet.OLEObjects.Add%20_%3CBR%20%2F%3EFilename%3A%3Dfpath%2C%20_%3CBR%20%2F%3ELink%3A%3DFalse%2C%20_%3CBR%20%2F%3EDisplayAsIcon%3A%3DTrue%2C%20_%3CBR%20%2F%3EIconFileName%3A%3D%22excel.exe%22%2C%20_%3CBR%20%2F%3EIconIndex%3A%3D0%2C%20_%3CBR%20%2F%3EIconLabel%3A%3DextractFileName(fpath)%3CBR%20%2F%3E%3CBR%20%2F%3EEnd%20Sub%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EPublic%20Function%20extractFileName(filePath)%3C%2FP%3E%3CP%3EFor%20i%20%3D%20Len(filePath)%20To%201%20Step%20-1%3CBR%20%2F%3EIf%20Mid(filePath%2C%20i%2C%201)%20%3D%20%22%5C%22%20Then%3CBR%20%2F%3EextractFileName%20%3D%20Mid(filePath%2C%20i%20%2B%201%2C%20Len(filePath)%20-%20i%20%2B%201)%3CBR%20%2F%3EExit%20Function%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3ENext%3C%2FP%3E%3CP%3EEnd%20Function%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-557938%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Robusfar
New Contributor

Dear all 
I've created an 'attach file'-button in my spreadsheet using the below macro.

 

I would however like for the icon of the attached file to be a generic green check mark instead of the excel.exe icon...

Can anyone help me modify the below macro to do that?

Br.

Robusfar

 


My macro:

 

Public Sub insertFile()

'Select the cell in which you want to place the attachment
Range("F11").Select

'Get file path
fpath = Application.GetOpenFilename("All Files,*.*", Title:="Select file")
If LCase(fpath) = "false" Then Exit Sub

'Insert file
ActiveSheet.OLEObjects.Add _
Filename:=fpath, _
Link:=False, _
DisplayAsIcon:=True, _
IconFileName:="excel.exe", _
IconIndex:=0, _
IconLabel:=extractFileName(fpath)

End Sub


Public Function extractFileName(filePath)

For i = Len(filePath) To 1 Step -1
If Mid(filePath, i, 1) = "\" Then
extractFileName = Mid(filePath, i + 1, Len(filePath) - i + 1)
Exit Function
End If
Next

End Function

 

Related Conversations
flashing a white screen while open new tab
cntvertex in Discussions on
13 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
22 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
PacketMon Components are not loading in WAC 1909
HotCakeX in Windows Admin Center on
2 Replies