I have a macro that works well to insert multiple pictures into multiple different locations from a specified directory, but it seems to run a little slow. (I've noticed a difference between Excel2003 and Excel2010).
Below is a portion of the code for one of the 1st loops, but I am specifically wondering about the following bit:
I feel like there is a cleaner more efficient way to do this than using the "Select". Any help would be greatly appreciated as well as confirmation that this is the most efficient way to accomplish inserting the picture.
Below is a portion of the code for one of the 1st loops, but I am specifically wondering about the following bit:
Code:
Cells(sr_offset + 21 * i, sc_offset + 11 * j).Select
ActiveSheet.Pictures.Insert(SEM_dir & "\" & RUN_dir & "\" & SEM_pic & ".jpg").Select
I feel like there is a cleaner more efficient way to do this than using the "Select". Any help would be greatly appreciated as well as confirmation that this is the most efficient way to accomplish inserting the picture.
Code:
Private Sub InsertSEM_Click()
' InsertSEM Macro
' Dimension variables
Dim SEM_dir As String
Dim RUN_dir As String
Dim SEM_pic As String
Dim row_offset As Integer
Dim col_offset As Integer
Dim sr_offset As Integer
Dim sc_offset As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim PicMsg As String
' Specifying variables
SEM_dir = Cells(3, 7).Value
RUN_dir = Cells(4, 7).Value
row_offset = 6
On Error GoTo line140
' Inserting SEM Pictures
' Inserts Page 1 Center SEM Pics
col_offset = 2
For i = 1 To 2 Step 1
For j = 1 To 2 Step 1
If Cells(row_offset + i, col_offset + j).Value = Empty Then
GoTo line80
Else
SEM_pic = Cells(row_offset + i, col_offset + j).Value
sr_offset = 25
sc_offset = -9
Cells(sr_offset + 21 * i, sc_offset + 11 * j).Select
ActiveSheet.Pictures.Insert(SEM_dir & "\" & RUN_dir & "\" & SEM_pic & ".jpg").Select
End If
line80:
Next j
Next i