การ insert รูปภาพให้ไปตามชีทที่ต้องการ ทำอย่างไรครับ
Posted: Fri Nov 29, 2019 3:05 pm
รบกวนช่วยแนะนำด้วยครับ
ผมต้องการจะบันทึกรูปภาพไป sheet ที่เลือกไว้ใน userfrom (แผนก) จะต้องแก้ไข code อย่างไรครับ
Code: Select all
Dim emptyRow As Long
Dim strPath As FileDialog
Sub InsertPicture(photoPath)
Dim sPicture As String, pic As Picture
'If sPicture = "False" Then Exit Sub
Sheet2.Select
Range("H" & emptyRow).Select
Set pic = ActiveSheet.Pictures.Insert(photoPath)
With pic
.ShapeRange.LockAspectRatio = msoFalse
.Height = ActiveCell.Height
.Width = ActiveCell.Width
.Top = ActiveCell.Top
.Left = ActiveCell.Left
.Placement = xlMoveAndSize
End With
Set pic = Nothing
End Sub
Sub sendData()
emptyRow = WorksheetFunction.CountA(Range("B:B")) + 1
Cells(emptyRow, 2).Value = UserForm1.TextBox1.Value
Cells(emptyRow, 3).Value = UserForm1.TextBox2.Value
Cells(emptyRow, 4).Value = UserForm1.TextBox3.Value
Cells(emptyRow, 5).Value = UserForm1.TextBox4.Value
Cells(emptyRow, 7).Value = UserForm1.TextBox5.Value
Cells(emptyRow, 6).Value = UserForm1.DTPicker1.Value
Call InsertPicture(strPath.SelectedItems(1))
End Sub
Sub insertPhotoToForm()
Set strPath = Application.FileDialog(msoFileDialogFilePicker)
strPath.AllowMultiSelect = False
strPath.Show
UserForm1.Image1.Picture = LoadPicture(strPath.SelectedItems(1))
End Sub