Visual Basicu näiteid: vorm, joonis, tekstifail Private Sub nupp1_Click() txtSentimeetrid = Str(Val(txtTollid) * 2.54) End Sub Private Sub nahtavaks_Click() Dim leht As Worksheet Set leht = Sheets("inimandmed") leht.Rows.Hidden = False End Sub Private Sub pnimeotsing_Click() Dim leht As Worksheet Dim rida As Range Dim reanr As Integer Set leht = Sheets("inimandmed") reanr = 1 Do While Len(Trim(leht.Cells(reanr, 1))) > 0 Set rida = leht.Rows(reanr) If txtPerekonnanimi.Text = leht.Cells(reanr, 2) Then rida.Hidden = False Else rida.Hidden = True End If reanr = reanr + 1 Loop End Sub Sub joonistus1() ActiveSheet.Shapes.AddShape msoShapeRectangle, 105, 144, 125.25, 135# ActiveSheet.Shapes.AddLine 165#, 96#, 268.5, 173.25 ActiveSheet.Shapes.AddShape(msoShapeOval, 300.75, 54#, 39#, 44.25).Select End Sub Sub kustuta() Dim kujund As Shape For Each kujund In Sheet1.Shapes kujund.Delete Next kujund End Sub Sub joonistus2() kustuta Sheet1.Shapes.AddLine 100, 50, 200, 85 End Sub Sub andmejoonis () kustuta Sheet1.Shapes.AddLine Selection.Offset(0, 1).Left, _ Selection.Top + Selection.Height / 2, _ Selection.Offset(0, 1).Left + Selection, _ Selection.Top + Selection.Height / 2 'iga joone otsa väike ring Sheet1.Shapes.AddShape msoShapeOval, _ Selection.Offset(0, 1).Left + Selection, _ Selection.Top, Selection.Height, Selection.Height End Sub Sub tekstifailikirjutus() Open "nimed.txt" For Append As #1 reanr = 1 Do While Len(Trim(Cells(reanr, 1))) > 0 Print #1, Cells(reanr, 1) reanr = reanr + 1 Loop Close #1 End Sub Sub tekstifaililugemine() Dim rida As String Open "c:\nimed.txt" For Input As #1 Do While Not EOF(1) Line Input #1, rida MsgBox (rida) Loop Close #1 End Sub Sub failinimed() Dim failinimi, failinimed failinimi = Dir("c:\*.*") While Len(failinimi) > 0 failinimed = failinimed & failinimi & vbCrLf failinimi = Dir Wend MsgBox failinimed End Sub Sub kirjutaHTML() Dim reanr, veerunr, ala As Range ActiveSheet.Range("a1").Select Set ala = ActiveCell.CurrentRegion 'lahtriga ühendatud ala Open Application.GetSaveAsFilename( _ "katsetus.html", "HTMLi failid (*.html), *.html", 1, _ "Veebilehe salvestamine", "Valmis" _ ) For Output As #1 Print #1, "
Nimi | Sünniaasta | Telefon | " & Chr(13) For reanr = 2 To ala.Rows.Count Print #1, "
" & ala.Cells(reanr, veerunr) & " | " & Chr(13) Next veerunr Next reanr Print #1, "