VBA
-
Apr 2, 2010 at 06:27 AM
rizvisa1
Posts4478Registration dateThursday January 28, 2010StatusContributorLast seenMay 5, 2022
-
Apr 6, 2010 at 11:52 AM
Hello,
Please help.
I have written a macro to pickup jpeg file from the directory and insert it into excel. I have issue with picking up jpeg file from the directory.
the error I get is Run-time error '1004'
Unable to get the insert property of the pictures class.
When I select Debug it select the line:-
ActiveSheet.Pictures.Insert("Z:\ACCDATA\IMAGES\" & picname & ".JPEG").Select 'Path to where pictures are stored
All the images are in the images subdirectory and they are all have JPEG file extention.
Thanks
My macro is
Sub test()
'''''''''''''''' insert_col in Col A and change the width'''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Insert image of the picture from Col.B into Col.A
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim picname As String
Dim pasteAt As Integer
Dim lThisRow As Long
lThisRow = 2
Do While (Cells(lThisRow, 2) <> "")
'Range("A6").Select 'This is where picture will be inserted
'pasteAt = Cells(lThisRow, 3)
pasteAt = lThisRow 'This is where picture will be inserted
'Dim picname As String
'picname = Range("B6") 'This is the picture name
picname = Cells(lThisRow, 2) 'This is the picture name
ActiveSheet.Pictures.Insert("Z:\ACCDATA\IMAGES" & picname & ".JPEG").Select 'Path to where pictures are stored
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This resizes the picture
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
With Selection
''''''''''''''' insert 6 rows at the top of the sheet''''''''''''''
Rows("1:9").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
''''''''''''''' End 6 rows at the top of the sheet''''''''''''''
'''''''''''''''reduce hight from A1:A7''''''''''''''
Rows("1:9").Select
Range("A7").Activate
Selection.RowHeight = 27
Range("A2").Select
'''''''''''''''End reduce hight from A1:A7''''''''''''''
''''''''''''''' change Row hight and ColumnWidth ''''''''''''''
Rows("10:6700").Select
Selection.RowHeight = 75
Selection.ColumnWidth = 20
''''''''''''''' End of change Row hight and ColumnWidth ''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''
'End Inserting image of the picture from Col.B into Col.A
''''''''''''''''''''''''''''''''''''''''''''''''''''''
ErrNoPhoto:
MsgBox "There is no more image to insert!" 'Shows message box if picture not found
Exit Sub
Range("B20").Select
End Sub