snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
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