I am trying to utilise the vba code that I got from here. When I run the macro, selenium webdriver will retrieve the link of the picture and put it near to Z#. However, sometimes after generating the QR image from the website, the generated QR image will have problem to move to the Y# cell and resize.
The debug will prompt at Set Pshp = Selection.ShapeRange.Item(1)
, showing "Object doesn't support this property or method" error.
As I will need to generate QR code for several rows of data, I am currently doing row by row.
As I said, the problem sometimes happens, but in a high frequency (90% of the time). Anyone mind to troubleshoot together? Thanks
For i = 6 To Sheet2.Range("D" & Application.Rows.Count).End(xlUp).Row
Application.StatusBar = i - 1 & "/" & Sheet2.Range("D" & Application.Rows.Count).End(xlUp).Row - 1
bot.FindElementByXPath("//input[contains(@type,'search')]").SendKeys (Sheet2.Range("D" & i))
bot.Wait 1500
Report = bot.FindElementByLinkText("EN").Attribute("href")
bot.Get Report
bot.Wait 1500
QRurl = bot.FindElementByXPath("//img[contains(@src,'QRimages')]").Attribute("src")
Sheet2.Range("Z" & i).Value = QRurl
Sheet2.Pictures.Insert(QRurl).Select
Set Pshp = Selection.ShapeRange.Item(1)
If Pshp Is Nothing Then GoTo lab
xcol = Sheet2.Range("Z" & i).Column - 1
Set xRg = Cells(Sheet2.Range("Z" & i).Row, xcol)
With Pshp
.LockAspectRatio = msoFalse
If .Width > xRg.Width Then .Width = xRg.Width * 9 / 10
If .Height > xRg.Height Then .Height = xRg.Height * 9 / 10
.Top = xRg.Top (xRg.Height - .Height) / 2
.Left = xRg.Left (xRg.Width - .Width) / 2
.Placement = xlMoveAndSize
End With
lab:
Set Pshp = Nothing
Range("Z6").Select
bot.Get "https://_/_/bulk_upload2_record.php"
bot.Wait 1000
Next i
CodePudding user response:
I found out that I need to run the macro on the sheet I specified, otherwise all generate image will be stuck at Z"i". I assigned my button at the "navigation" sheet, that is why it didn't work out well. I tried on other sheet and run the macro as well, same outcome. So my solution is just adding a line to activate sheet2 before the for loop.