Embbed Object but format size VBA

ryan_law2000

Well-known Member
Joined
Oct 2, 2007
Messages
738
Hello Everyone I have VBA that embeds an object but I want to be able to set the size of it.
Any ideas how to change this from the size of a cell to actually enter in the values of size that I need?
I also want it to always display "FIELD TICKET" as the icon text but cant seem to make it work.
Thanks

Code:
Sub AttachTicket()
     Dim vFile As String
     Dim objI As Object
     Dim rngI As Range

     For Each rngI In Range("J17")    'make range any size, or use Selection for flexibility
         vFile = Application.GetOpenFilename("All Files,*.*", Title:="Find file to insert")
         If LCase(vFile) = "false" Then Exit Sub
         Set objI = ActiveSheet.OLEObjects.Add(Filename:=vFile, Link:=False, DisplayAsIcon:=True, IconLabel:=vFile)
         objI.Left = rngI.Left
         objI.Top = rngI.Top
         objI.Height = rngI.Height
         objI.Width = rngI.Width
         'If objI.Height > rngI.Height Then
             'objI.Height = rngI.Height
         'End If
     Next rngI
      With Worksheets("Main").Range("K18")
        .Value = "<-- Attached! Double Click to View"
        End With
     
 End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

yky

Well-known Member
Joined
Jun 7, 2011
Messages
1,881
Office Version
  1. 2010
Platform
  1. Windows
Code:
[COLOR=#333333]'If objI.Height > rngI.Height Then
[/COLOR]'objI.Height = rngI.Height [COLOR=#333333]         
'End If[/COLOR]
What you want is :

rngI.RowHeight=objI.Height
 
Last edited:
Upvote 0

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
21,000
Office Version
  1. 365
Platform
  1. Windows
I also want it to always display "FIELD TICKET" as the icon text but cant seem to make it work.

Try...

Code:
IconLabel:="FIELD TICKET"
 
Upvote 0

Forum statistics

Threads
1,195,674
Messages
6,011,098
Members
441,582
Latest member
Topkapi

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
Top