+ Reply to Thread
Results 1 to 6 of 6

VBA - Inserting, Selecting, Moving Pictures?

Hybrid View

  1. #1
    Registered User
    Join Date
    04-08-2009
    Location
    New Orleans, LA
    MS-Off Ver
    Excel 2007
    Posts
    4

    VBA - Inserting, Selecting, Moving Pictures?

    I am new to this forum and have a problem that I have been working on for the past few weeks.

    I am trying to Insert pictures into a worksheet in a grid or table format. It does not have have to be any specific order, just re-sized to 19% and moved to actually be able to view each one, as they are stacked on top of each other upon insertion.

    If the "Insert" part is the hang up, we can insert the pictures first and then have the macro take over from there.

    I can post the code that I have been working with, but it would probably cause more harm than good. But I have been using the record function, which works for the pictures that are already inserted, but once the file names change, it bugs out.

    I am using Excel 2003.

    I really appreciate the help.
    Last edited by Luckdow; 04-08-2009 at 09:28 AM. Reason: Description

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: VBA - Inserting, Selecting, Moving Pictures?

    Hi, You could have a play with this.
    This code originally related to small pictures of Flags that had been already inserted in the sheet.
    The code just arranges then across & down the sheet.

    Dim oPic As Shape, allpic As String
     Dim oP As String, ac As Integer, c, t
     Me.Pictures.Visible = True
      c = 10
      t = 10
      For Each oPic In Me.Shapes
       If oPic.Type = 13 Then
            With oPic 'ActiveSheet.Shapes(oPic.Name)
                .Width = 0
                .Height = 50
                .Top = t
                .Left = c
                 c = c + 70
                 If c >= 560 Then t = t + 70
                 c = IIf(c >= 560, 10, c)
        .ScaleHeight 0.75, msoFalse, msoScaleFromTopLeft
        End With
             End If
                  
         Next oPic
    Regards Mick

  3. #3
    Registered User
    Join Date
    04-08-2009
    Location
    New Orleans, LA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VBA - Inserting, Selecting, Moving Pictures?

    Thanks for the quick reply. Do I need to do anything special to have that code work, other than copying and pasting? (Forgive my beginner knowledge)

    It is returning a "Compile Error: Invalid outside procedure" and the "True" in the code is highlighted.

    Thanks again for your help.

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: VBA - Inserting, Selecting, Moving Pictures?

    Hi, I don't quite understand your error ,but try this.
    Right click your sheet tab. This sheet should have pictures (visible) Inserted from the drawing tool bar.
    Select "View code", VB window appears.
    From the VB Toolbar Select "Insert", "Module". New window appears. Paste the entire code below into the new window.
    Close VB Window.
    Click "Alt+F8" Macro Dialog box appears, Select the code "Pic", Click run fron the Right hand side Menu.
    Pictures in you sheet should be aligned, across & down the sheet.(Hopefully)
    Sub pic()
    Dim oPic As Shape, allpic As String
     Dim oP As String, ac As Integer, c, t
     ActiveSheet.Pictures.Visible = True
      c = 10
      t = 10
      For Each oPic In ActiveSheet.Shapes
       If oPic.Type = 13 Then
            With oPic 'ActiveSheet.Shapes(oPic.Name)
                .Width = 0
                .Height = 50
                .Top = t
                .Left = c
                 c = c + 70
                 If c >= 560 Then t = t + 70
                 c = IIf(c >= 560, 10, c)
        .ScaleHeight 0.75, msoFalse, msoScaleFromTopLeft
        End With
             End If
                  
         Next oPic
    End Sub
    Regards Mick

  5. #5
    Registered User
    Join Date
    04-08-2009
    Location
    New Orleans, LA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VBA - Inserting, Selecting, Moving Pictures?

    Mick,

    That is great!!! It is working like a charm. One question, what part of the code do I need to change to adjust the resulting size? In other words, the pictures are reduced, which I want, but not quite this small?

    Thanks again, you are a huge help!!!!

  6. #6
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: VBA - Inserting, Selecting, Moving Pictures?

    hi, What you need to do is play with the Variables"c" & "t", as shown below.
    I should change one Variable at a time and then review the result.
    It very much dependent on what you want to achieve.
    Sub Pic()
    Dim oPic As Shape, allpic As String
     Dim oP As String, ac As Integer, c, t
     ActiveSheet.Pictures.Visible = True
      c = 10 ' These are start Borders (Left)
      t = 10 ' These are start Borders (Top)
      For Each oPic In ActiveSheet.Shapes
       If oPic.Type = 13 Then
            With oPic
                .Width = 0
                .Height = 120 '50'(Change Here)
                .Top = t
                .Left = c
                 c = c + 150 '70'(Change Here)
                 
              '(Change "560" Here "Both Lines Below")
                 If c >= 400 Then t = t + 150 '70'(Change Here)
                 c = IIf(c >= 400, 10, c) '560'(Change Here)
    
        .ScaleHeight 0.75, msoFalse, msoScaleFromTopLeft
        End With
             End If
                  
         Next oPic
      End Sub
    Regards Mick

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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