Bermain dengan image (gambar) jadi kepikiran untuk menampilkan gambar dengan bantuan Macro Vba Excel, yang menempatkan gambar di Sheet, UserForm dan Folder.
Insert :
Berikut bila sudah jadi saat di RUN
Pertama Siapkan 1 buah file excel dengan nama "InsertFoto" Ganti sendiri save as dengan format Xls/Xlsm/Xlsb. Tekan (ALT+F11) untuk menuju halaman Macro Vba Excel.
Buat 1 userform
Insert :
ComboButton1.Caption = "Cari Foto"
ComboButton2.Caption = "Hapus Foto"
Label1.caption = "www.pm4x.tk -> Belajar Insert Foto di Form, SheetsActive dan Folder"
Image1.picture
Untuk String Macro :
ComboButton1
Private Sub CommandButton1_Click()
On Error Resume Next
Dim filter As String, Title As String, FileX As String
Dim SourceFile, DestinationFile
Dim Fileku
Dim lokasi
X.SetFocus
filter = "Format Foto Jpg(*.jpg),*.jpg"
Title = "Pencarian Foto"
FileX = Application.GetOpenFilename(filter, , Title)
lokasi = ThisWorkbook.Path
NamaFile = "Insertfoto"
DestinationFile = lokasi & "\" & NamaFile & ".jpg"
FileCopy FileX, DestinationFile
UserForm1.Picture = LoadPicture(FileX)
ActiveSheet.Pictures.insert (FileX)
LoadPicture(FileX).Export (lokasi)
CommandButton1.Visible = False
CommandButton3.Visible = True
End Sub
ComboButton2
Private Sub CommandButton2_Click()
Dim lokasi
ActiveSheet.Pictures.Delete
UserForm1.Picture = Image2.Picture
lokasi = ThisWorkbook.Path
On Error Resume Next
Kill lokasi & "\Insertfoto.jpg"
On Error GoTo 0
CommandButton3.Visible = False
CommandButton1.Visible = True
End Sub
Userform
Private Sub UserForm_Activate()
Me.Caption = Label1
CommandButton3.Visible = False
UserForm1.Picture = Image2.Picture
End Sub
Untuk memastikan berjalan tambahkan string pada Workbook
Option Explicit
Private Sub Workbook_Open()
UserForm1.Show
End Sub
Semoga dapat membantu dan bermanfaat
0 komentar
Posting Komentar