+ Reply to Thread
Results 1 to 2 of 2

Build Buttons in Columns with click function

  1. #1
    Registered User
    Join Date
    07-04-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    17

    Build Buttons in Columns with click function

    This is my first post so bear with me if I have not provided enough information.

    I have a list of Serial Numbers on Excel and their associated photographs of the item in a folder. I am trying to build a column of buttons next to the serial numbers which has the number on the button. The button when clicked should then open the photo from the external folder and display on the worksheet.

    I can do this for each individual button and corresponding photo but I have over 200 numbers/photographs and am trying to automate the process.

    I have managed to create a column of buttons using in the sheet 1 object page:

    Option Explicit

    Sub createButtons()
    Dim theButton As OLEObject
    Dim rngRange As Range
    Dim i As Integer

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set rngRange = Sheets(1).Range("$B2")

    For i = 0 To 9
    If rngRange.Offset(i, 0).Value <> "" Then
    With rngRange.Offset(i, 1)
    Set theButton = ActiveSheet.OLEObjects.Add _
    (ClassType:="Forms.CommandButton.1", _
    Left:=.Left, _
    Top:=.Top, _
    Height:=.Height, _
    Width:=.Width)

    theButton.Name = "cmd" & rngRange.Offset(i, 0).Value
    theButton.Object.Caption = rngRange.Offset(i, 0).Value

    End With
    End If
    Next i

    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    End Sub


    However I am struggling to get the buttons to do anything. Please could someone help? I am used to working in C/C++/Matlab etc and therefore the foibles of VBA I am not quite akin with yet. Should the above code or any other code be in a module or in the worksheet?

    Thanks in advance

  2. #2
    Registered User
    Join Date
    07-04-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Build Buttons in Columns with click function

    Is there anyone out there that can help?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1