Consulting

Results 1 to 3 of 3

Thread: Renaming inserted Object

  1. #1
    VBAX Newbie
    Joined
    Feb 2019
    Posts
    4
    Location

    Renaming inserted Object

    Dear All

    Hope you are doing well.

    When object/shape is inserted in spreadsheet it aoutomatically takes a name like "Object##", Is there a way to give specific name to taht object?

    for example i loaded a file into the sheet as object I want to rename it as "Report1", kindly want to know if that's possible.
    Sub LoadReport1()    
    Filename = Application.GetOpenFilename(Title:="Please choose a file to open", FileFilter:="Excel Files *.xls* (*.xls*),")
        ActiveSheet.OLEObjects.Add(Filename:=Filename, Link:=False, DisplayAsIcon:=True, IconFileName:= _
        "C:\Windows\Installer\{90150000-0011-0000-1000-0000000FF1CE}\xlicons.exe", _
        IconIndex:=0, IconLabel:= _
        Filename).Select
    End Sub
    Thank you

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this

    Sub LoadReport1()
    Dim myBook As Object
    Dim Filename As String
    
        Filename = Application.GetOpenFilename(Title:="Please choose a file to open", _
                                               FileFilter:="Excel Files *.xls* (*.xls*),")
        Set myBook = ActiveSheet.OLEObjects.Add(Filename:=Filename, _
                                                Link:=False, _
                                                DisplayAsIcon:=True, _
                                                IconFileName:="C:\Windows\Installer\{90150000-0011-0000-1000-0000000FF1CE}\xlicons.exe", _
                                                IconIndex:=0, _
                                                IconLabel:=Filename)
        myBook.Name = "MyBook"
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Feb 2019
    Posts
    4
    Location
    Dear Xld

    Thank you,

    SOLVED

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •