Deleting an embedded file

bruty

Active Member
Joined
Jul 25, 2007
Messages
456
Office Version
  1. 365
Platform
  1. Windows
I have the following code used to attach a file to a spreadsheet:

Code:
VarFile = Application.GetOpenFilename("All Files (*.*), *.*")
        If VarFile <> False Then
            ActiveSheet.OLEObjects.Add(Filename:= _
            VarFile, Link:= _
            False, DisplayAsIcon:=True, IconFileName:= _
            "C:\WINDOWS\Installer\{90110409-6000-11D3-8CFE-0150048383C9}\wordicon.exe", _
            IconIndex:=0, IconLabel:= _
            VarFile).Select
        End If

Is there anyway of giving this object a name? I need to name it so that I can easily delete the file.

If I can't name it, is there an easy way to select and delete the file?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Like this?

Code:
Sub Test()
    VarFile = Application.GetOpenFilename("All Files (*.*), *.*")
    If VarFile <> False Then
        ActiveSheet.OLEObjects.Add(Filename:= _
        VarFile, Link:= _
        False, DisplayAsIcon:=True, IconFileName:= _
        "C:\WINDOWS\Installer\{90110409-6000-11D3-8CFE-0150048383C9}\wordicon.exe", _
        IconIndex:=0, IconLabel:= _
        VarFile).Select
        Selection.Name = "VarFile"
    End If
End Sub
 
Sub Delete()
    ActiveSheet.OLEObjects("VarFile").Delete
End Sub
 
Upvote 0
Don't know the problem, but this doesn't seem to work.

Using this toname the file:
Code:
VarFile = Application.GetOpenFilename("All Files (*.*), *.*")
        If VarFile <> False Then
            ActiveSheet.OLEObjects.Add(Filename:= _
            VarFile, Link:= _
            False, DisplayAsIcon:=True, IconFileName:= _
            "C:\WINDOWS\Installer\{90110409-6000-11D3-8CFE-0150048383C9}\wordicon.exe", _
            IconIndex:=0, IconLabel:= _
            VarFile).Select
            Selection.Name = "JobDesc"
        End If

And this to delete the object:
Code:
'On Error Resume Next
    'ActiveSheet.Shapes("JobDesc").Delete
    'ActiveSheet.OLEObjects("VarFile").Delete

They are messaged out at the moment because neither of them work - I tried the shapes bit instead of OLEObjects as that's what came up when I recorded a macro delting the file.
 
Upvote 0
Ignore me - realised the name hasn't changed from VarFiel to Job Desc
 
Upvote 0

Forum statistics

Threads
1,222,095
Messages
6,163,881
Members
451,864
Latest member
Pandorom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top