Extracting images from a database but named with a specific cell content.
Closed
Gordon02812
Posts
11
Registration date
Thursday 28 November 2019
Status
Member
Last seen
9 December 2019
-
29 Nov 2019 à 09:35
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 10 Dec 2019 à 11:50
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 10 Dec 2019 à 11:50
Related:
- Summertime saga pictures
- How do i find a specific video on youtube - Guide
- Fifa 23 downloadable content - Download - Sports
- Access database download - Download - Databases
- Summertime saga downloadable content - Download - Adult games
- How to disable images on chrome android - Guide
3 responses
TrowaD
Posts
2921
Registration date
Sunday 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
3 Dec 2019 à 12:16
3 Dec 2019 à 12:16
Hi Gordon,
"Image #" is the default name given. If you want to change it to the values in column B, add the following line:
Selection.ShapeRange.Name = cell.Offset(0, 1)
Insert it after this line:
If Pshp Is Nothing Then GoTo lab
Best regards,
Trowa
"Image #" is the default name given. If you want to change it to the values in column B, add the following line:
Selection.ShapeRange.Name = cell.Offset(0, 1)
Insert it after this line:
If Pshp Is Nothing Then GoTo lab
Best regards,
Trowa
So the problem isn't with the posted code, it is with the mystery script?
Gordon02812
Posts
11
Registration date
Thursday 28 November 2019
Status
Member
Last seen
9 December 2019
30 Nov 2019 à 09:11
30 Nov 2019 à 09:11
If you mean by “code” the code/script that I wrote originally, then that works just fine. It finds all the images and displays them in excel.
The problem is that I want the images to be named with the product code instead of just calling it “image 1” etc.
I feel as though the issue lies on line 10 (filenam = cell)
The problem is that I want the images to be named with the product code instead of just calling it “image 1” etc.
I feel as though the issue lies on line 10 (filenam = cell)
Well, it runs right for me, as soon as you place the line back in to name the filename. Not certain what the issue is. Great job as always on this, TrowaD (you know who this is, but I no longer have access)!
Gordon02812
Posts
11
Registration date
Thursday 28 November 2019
Status
Member
Last seen
9 December 2019
6 Dec 2019 à 04:38
6 Dec 2019 à 04:38
Ok that's really interesting! So I'm doing something wrong clearly.... When you say "as soon as you place the line back in to name the filename." do you mean the "filenam = cell"? If not could you send me the exact script that you used? Fro the life of me, I was sure Trowa's idea was going to work.
LamoIdiot5
>
Gordon02812
Posts
11
Registration date
Thursday 28 November 2019
Status
Member
Last seen
9 December 2019
6 Dec 2019 à 07:21
6 Dec 2019 à 07:21
Yes that is what I meant.
Gordon02812
Posts
11
Registration date
Thursday 28 November 2019
Status
Member
Last seen
9 December 2019
>
LamoIdiot5
6 Dec 2019 à 07:33
6 Dec 2019 à 07:33
Yep, well that's exactly what I did but somehow I'm not getting the same results.... Can you see any differences between your script and mine?
Gordon02812
Posts
11
Registration date
Thursday 28 November 2019
Status
Member
Last seen
9 December 2019
6 Dec 2019 à 04:55
6 Dec 2019 à 04:55
Ok this what my script looks like now, what am I missing!?
Sub URLPictureInsert()
'Updateby Extendoffice 20161116
Dim Pshp As Shape
Dim xRg As Range
Dim xCol As Long
On Error Resume Next
Application.ScreenUpdating = False
Set Rng = ActiveSheet.Range("A1:A6")
For Each cell In Rng
filenam = cell
ActiveSheet.Pictures.Insert(filenam).Select
Set Pshp = Selection.ShapeRange.Item(1)
If Pshp Is Nothing Then GoTo lab
Selection.ShapeRange.Name = cell.Offset(0, 1)
xCol = cell.Column + 1
Set xRg = Cells(cell.Row, xCol)
With Pshp
.LockAspectRatio = msoFalse
.Width = 100
.Height = 100
.Top = xRg.Top + (xRg.Height - .Height) / 2
.Left = xRg.Left + (xRg.Width - .Width) / 2
End With
lab:
Set Pshp = Nothing
Range("A1").Select
Next
Application.ScreenUpdating = True
End Sub
Sub URLPictureInsert()
'Updateby Extendoffice 20161116
Dim Pshp As Shape
Dim xRg As Range
Dim xCol As Long
On Error Resume Next
Application.ScreenUpdating = False
Set Rng = ActiveSheet.Range("A1:A6")
For Each cell In Rng
filenam = cell
ActiveSheet.Pictures.Insert(filenam).Select
Set Pshp = Selection.ShapeRange.Item(1)
If Pshp Is Nothing Then GoTo lab
Selection.ShapeRange.Name = cell.Offset(0, 1)
xCol = cell.Column + 1
Set xRg = Cells(cell.Row, xCol)
With Pshp
.LockAspectRatio = msoFalse
.Width = 100
.Height = 100
.Top = xRg.Top + (xRg.Height - .Height) / 2
.Left = xRg.Left + (xRg.Width - .Width) / 2
End With
lab:
Set Pshp = Nothing
Range("A1").Select
Next
Application.ScreenUpdating = True
End Sub
TrowaD
Posts
2921
Registration date
Sunday 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
9 Dec 2019 à 11:58
9 Dec 2019 à 11:58
I figured as much M :)
3 Dec 2019 à 13:37
Thank you so much for getting involved. I tried your suggestion but not joy. Exactly the same outcome "Image#".
Hers what I did:
Sub URLPictureInsert()
'Updateby Extendoffice 20161116
Dim Pshp As Shape
Dim xRg As Range
Dim xCol As Long
On Error Resume Next
Application.ScreenUpdating = False
Set Rng = ActiveSheet.Range("A1:A6")
For Each cell In Rng
ActiveSheet.Pictures.Insert(filenam).Select
Set Pshp = Selection.ShapeRange.Item(1)
If Pshp Is Nothing Then GoTo lab
Selection.ShapeRange.Name = cell.Offset(0, 1)
xCol = cell.Column + 1
Set xRg = Cells(cell.Row, xCol)
With Pshp
.LockAspectRatio = msoFalse
.Width = 100
.Height = 100
.Top = xRg.Top + (xRg.Height - .Height) / 2
.Left = xRg.Left + (xRg.Width - .Width) / 2
End With
lab:
Set Pshp = Nothing
Range("A1").Select
Next
Application.ScreenUpdating = True
End Sub
On this test nothing happens at all. Notice I added you line and removed filenam = cell. When I leave filenam = cell in, it finds the images and gives them a generic name.
Any ideas?
Best,
Gordon.
9 Dec 2019 à 09:33
I'm beginning to feel this thread has fallen silent, any chance you could take a look at it again for me?
Best,
Gordon.
9 Dec 2019 à 11:56
Sorry for the wait, only active on Monday and Tuesday in December.
Nothing is happening, because you didn't define "filenam". So either put back the code line "filenam = cell" or replace "filenam" with "cell.value".
Other then that it should work:
Column A shows filename, column B shows image name. With the image selected, the image name is shown in the top left.
The name contains a space, because I thought that might be the issue, since you are not allowed to use spaces when naming ranges. But with images it still works, same goes
Maybe you had something else in mind, like selecting the image name the same as a named range?
Best regards,
Trowa
9 Dec 2019 à 14:08
No problem, I appreciate your help! Here's a screenshot of what I'm looking at...
As you can see, the images download but they don't have a name. When I right click to "Save As", to get an idea what the image is called, it's always called "Picture 1.png". Is this a Mac issue?
So the address of the image is in "A", and the image should be called whatever is in "B" on the same row...
Best,
Gordon.
9 Dec 2019 à 14:10