次のコードを使用してスプレッドシートに画像を追加しようとしています。vbaは形状を追加し、3秒待ってから削除します
Sub InsertPic()
Dim pic As String 'file path of pic
Dim myPicture As Picture 'embedded pic
Dim rng As Range 'range over which we will iterate
Dim cl As Range 'iterator
Set rng = Range("C5") '<~~ Modify this range as needed. Assumes image link URL in column A.
For Each cl In rng
pic = "https://openclipart.org/image/2400px/svg_to_png/167549/Kliponious-green-tick.png"
Set myPicture = ActiveSheet.Pictures.Insert(pic)
'
'you can play with this to manipulate the size & position of the picture.
' currently this shrinks the picture to fit inside the cell.
With myPicture
.ShapeRange.LockAspectRatio = msoFalse
.Width = 40
.Height = cl.Height
.Top = Rows(cl.row).Top - 2
.Left = Columns(cl.Column).Left + 10
End With
'
Next
Application.Wait (Now + TimeValue("00:00:03"))
With myPicture
.delete
End With
End Sub
3秒後に、画像を削除します。
何らかの理由で、vbaが待機せず、画像を直ちに削除します。
私が間違っていることを誰かに見せてもらえますか?ありがとう
すぐに問題を解決するには、1分に変更してみてください。それはまだ遅れていないのですか?そうでない場合は、コードを実行して( 'F8'を使用)、何らかの理由でその行がスキップされるかどうかを確認します。 – BruceWayne
'TimeValue'ではなく' CDate( "00:00:03") 'を試してください。ちょうど推測。私はいつもCDateを使います。 –
代わりに 'Application.Wait Now + TimeSerial(0、0、3)'を試してください。地域の設定によって影響を受けません。 – Comintern