Situs Dosen STKIP Siliwangi Bandung - Martin Bernard, S.Pd., M.Pd

Artikel Umum

Membuat Kalkulator dengan VBA PowerPoint

Dipublikasikan pada : 29 April 2016. Kategori : .

Kode-kode untuk membuat Kalkulator

Private Sub CommandButton1_Click()
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text + “1”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Name = “Algerian”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Size = 40
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text + “1”

End Sub

Private Sub CommandButton10_Click()
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text + “0”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Name = “Algerian”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Size = 40
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text + “0”

End Sub

Private Sub CommandButton11_Click()
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = “”
TextBox1.Text = “”
TextBox2.Text = “”
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = “”
ActivePresentation.Slides(2).Shapes(“kalimat”).TextFrame.TextRange.Text = “Masukan Nilai Pertama”
ActivePresentation.Slides(2).Shapes(“kalimat”).Fill.ForeColor.RGB = vbMagenta

End Sub

Private Sub CommandButton12_Click()
Label1.Caption = 1
Label2.Caption = 1
Call operasi
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text + ” + ”
ActivePresentation.Slides(2).Shapes(“kalimat”).TextFrame.TextRange.Text = “Masukan Nilai Kedua lalu tekan sama dengan (=)”
ActivePresentation.Slides(2).Shapes(“kalimat”).Fill.ForeColor.RGB = vbRed

End Sub

Private Sub CommandButton13_Click()
Label1.Caption = 1
Label2.Caption = 2
Call operasi
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text + ” – ”
ActivePresentation.Slides(2).Shapes(“kalimat”).TextFrame.TextRange.Text = “Masukan Nilai Kedua lalu tekan sama dengan (=)”
ActivePresentation.Slides(2).Shapes(“kalimat”).Fill.ForeColor.RGB = vbGreen

End Sub

Private Sub CommandButton14_Click()
Label1.Caption = 1
Label2.Caption = 3
Call operasi
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text + ” x ”
ActivePresentation.Slides(2).Shapes(“kalimat”).TextFrame.TextRange.Text = “Masukan Nilai Kedua lalu tekan sama dengan (=)”
ActivePresentation.Slides(2).Shapes(“kalimat”).Fill.ForeColor.RGB = vbBlue

End Sub

Private Sub CommandButton15_Click()
Label1.Caption = 1
Label2.Caption = 4
Call operasi
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text + ” : ”
ActivePresentation.Slides(2).Shapes(“kalimat”).TextFrame.TextRange.Text = “Masukan Nilai Kedua lalu tekan sama dengan (=)”
ActivePresentation.Slides(2).Shapes(“kalimat”).Fill.ForeColor.RGB = RGB(150, 0, 75)

End Sub

Private Sub CommandButton16_Click()
Label1.Caption = 2
Call operasi
Select Case Label2.Caption
Case 1
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
Case 2
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = Val(TextBox1.Text) – Val(TextBox2.Text)
Case 3
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = Val(TextBox1.Text) * Val(TextBox2.Text)
Case 4
If TextBox2.Text = 0 Then
MsgBox “tidak boleh memasuki nilai nol”
TextBox2.Text = “”
Label1.Caption = 1
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = TextBox1.Text + ” : ”
Else
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = Val(TextBox1.Text) / Val(TextBox2.Text)
End If
End Select
ActivePresentation.Slides(2).Shapes(“kalimat”).TextFrame.TextRange.Text = “Hapus Tekan (ANS)”
ActivePresentation.Slides(2).Shapes(“kalimat”).Fill.ForeColor.RGB = vbBlack

End Sub

Private Sub CommandButton2_Click()
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text + “2”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Name = “Algerian”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Size = 40
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text + “2”

End Sub

Private Sub CommandButton3_Click()
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text + “3”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Name = “Algerian”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Size = 40
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text + “3”

End Sub

Private Sub CommandButton4_Click()
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text + “4”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Name = “Algerian”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Size = 40
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text + “4”

End Sub

Private Sub CommandButton5_Click()
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text + “5”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Name = “Algerian”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Size = 40
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text + “5”

End Sub

Private Sub CommandButton6_Click()
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text + “6”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Name = “Algerian”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Size = 40
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text + “6”

End Sub

Private Sub CommandButton7_Click()
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text + “7”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Name = “Algerian”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Size = 40
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text + “7”

End Sub

Private Sub CommandButton8_Click()
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text + “8”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Name = “Algerian”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Size = 40
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text + “8”

End Sub

Private Sub CommandButton9_Click()
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text + “9”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Name = “Algerian”
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Font.Size = 40
ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text = ActivePresentation.Slides(2).Shapes(“kotak”).TextFrame.TextRange.Text + “9”

End Sub

Sub operasi()
If Label1.Caption = 1 Then
TextBox1.Text = ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = “”
Else
If Label1.Caption = 2 Then
TextBox2.Text = ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text
ActivePresentation.Slides(2).Shapes(“layar”).TextFrame.TextRange.Text = “”
Label1.Caption = 0
End If
End If
End Sub

Private Sub Label2_Click()

End Sub

untuk melihat gambaran dapat dilihat disini