×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VB to Resize inserted object into Cell on Excel Worksheet

VB to Resize inserted object into Cell on Excel Worksheet

VB to Resize inserted object into Cell on Excel Worksheet

(OP)
Hi Can anyone please help with the following

I have the following code below to insert an object into selected Cells in excel

When the object icon is inserted it's size is bigger than the cell. I would like to adjust the icon to a specific size or automatically fit the cell

Is this possible in VB and if yes could you please help me with the code

Thanks

Here is my current code

Sub Button1_Click()
Dim vFile As Variant
Dim CSel As String
Set PreAttDocs = [D1]
CSel = "C7"
If Range(CSel).Value = 1 Then CSel = "D7"
If Range(CSel).Value = 1 Then CSel = "E7"
If Range(CSel).Value = 1 Then CSel = "F7"
If Range(CSel).Value = 1 Then CSel = "G7"
If Range(CSel).Value = 1 Then CSel = "H7"
If Range(CSel).Value = 1 Then CSel = "I7"
If Range(CSel).Value = 1 Then CSel = "J7"
If Range(CSel).Value = 1 Then CSel = "K7"
Range(CSel).Select
vFile = Application.GetOpenFilename("All Files,*.*", Title:="Find file to insert")
If LCase(vFile) = "false" Then Exit Sub
FN = InStrRev(vFile, "\", -1, vbTextCompare) + 1
FN2 = Mid(vFile, FN)
ActiveSheet.OLEObjects.Add Filename:= _
vFile, Link:= _
False, DisplayAsIcon:=True, IconFileName:= _
"C:\WINNT\Installer\{90140000-0011-0000-0000-0000000FF1CE}\icons.exe", _
IconIndex:=0, IconLabel:=FN2
Range(CSel).Value = 1
End Sub

RE: VB to Resize inserted object into Cell on Excel Worksheet

Hi,

CODE

Sub Button1_Click()
    Dim vFile As Variant
    Dim CSel As String
    Set PreAttDocs = [D1]
    CSel = "C7"
    If Range(CSel).Value = 1 Then CSel = "D7"
    If Range(CSel).Value = 1 Then CSel = "E7"
    If Range(CSel).Value = 1 Then CSel = "F7"
    If Range(CSel).Value = 1 Then CSel = "G7"
    If Range(CSel).Value = 1 Then CSel = "H7"
    If Range(CSel).Value = 1 Then CSel = "I7"
    If Range(CSel).Value = 1 Then CSel = "J7"
    If Range(CSel).Value = 1 Then CSel = "K7"
    Range(CSel).Select
    
    vFile = Application.GetOpenFilename("All Files,*.*", Title:="Find file to insert")
    If LCase(vFile) = "false" Then Exit Sub
    FN = InStrRev(vFile, "\", -1, vbTextCompare) + 1
    FN2 = Mid(vFile, FN)
    ActiveSheet.OLEObjects.Add Filename:= _
    vFile, Link:= _
    False, DisplayAsIcon:=True, IconFileName:= _
    "C:\WINNT\Installer\{90140000-0011-0000-0000-0000000FF1CE}\icons.exe", _
    IconIndex:=0, IconLabel:=FN2
    Range(CSel).Value = 1
    
    With ActiveSheet.Shapes(ActiveSheet.Shapes.Count).OLEFormat.Object.ShapeRange
        .Left = Range(CSel).Left
        .Top = Range(CSel).Top
        .Width = Range(CSel).Width
        .Height = Range(CSel).Height
    End With
End Sub 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: VB to Resize inserted object into Cell on Excel Worksheet

(OP)
Skip

Excellent and worked first time

Many Thanks for you help

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close