Posts filed under ‘Vba Excel’

vba Bekerja dengan Workbooks

Berikut ini beberapa procedure vba yang digunakan untuk mengecek….

(Kode-kode berikut diperoleh dari OZGRID)

  • Apakah Workbook terbuka atau tidak.
  • Apakah Workbook ada dalam  file dan folder .
  • membuka Semua Workbooks folder tertentu .
  • Apakah  Worksheet tertentu ada dalam active Workbook .
  • Apakah  nama range tertentu ada dalam active Workbook .
  • A range is hidden by Auto Filters .
  • Count how many pages will be printed .
 (more…)

April 12, 2009 at 5:44 am 3 comments

Custom Function untuk Excel

Berikut adalah contoh custom function untuk excel.

untuk melihat semua fungsi dan contoh pemakaiannya  download file excel custom function di sini :

Fungsi terdiri dari :

(more…)

March 29, 2009 at 4:27 pm Leave a comment

Menampilkan Pesan Pada Workbook

Berikut adalah contoh VBA Excel yang dapat digunakan sebagai antar muka dengan user yang menampilkan pesan pada saat user membuka workbook (file) excel.  Selain menampilkan pesan, kegunaan dari sub routine ini bisa dikembangkan menjadi counter (penghitung) berapa kali user memakai workbook.  Misal kita memiliki aplikasi yang dikembangkan dengan excel yang harus berbayar, dan memperbolehkan user untuk memakai beberapa kali (uji coba) sebelum workbook tersebut dibayar.

Berikut tampilannya:     Download File pesan dng Counter workbook.xls

pesan

March 13, 2009 at 3:00 am 2 comments

eBook on Ms Office VBA

Advancing Your Office 2007 Power: Using Visual Basic
By Greg Perry

You can automate many routine tasks that you perform with Office 2007’s products by recording your keystrokes and storing them in a macro. You can easily assign the macro to a keystroke such as Ctrl+Shift+F12 and Word or Excel will zip through your automated commands the moment you press the keys.
Recorded macro keystrokes have been around for years and many Office users are familiar with them. The only drawback is they are simple and don’t go the extra mile when you want something really automated.  Read more on Office2007withVisualBasic.pdf size : 206.65 KB

March 6, 2009 at 7:09 pm 1 comment

FUNGSI EXCEL HITUNG KATA

Kadang kita perlu mengetahui berapa jumlah kata yang kita tulis dalam Workbooks atau Worksheet Ms Excel. Dalam Excel tidak ada fungsi khusus yang dapat digunakan untuk menghitung jumlah kata. Oleh karena itu perlu dibuat fungsi untuk menghitung kata dengan menggunakan VBA. However, you can count the number of words with a simple VBA macro.

Sub Procedure di bawah ini akan menghitung berapa jumlah kata yang ada di dalam ActiveSheet (sheet yang aktif) dan menampilkannya dalam Kotak Pesan (Message Box). Contoh file dapat di download adalah (Download file : hitung-kata.zip)

(more…)

January 17, 2009 at 4:53 am 2 comments

Improving Recorded Macros

The good way to learn the basics of VBA is to record a macro and see how Excel writes its own code. Often, though, recorded macros contain much more code than is necessary. The following exercises demonstrate how you can improve and streamline code that has been produced by a recorded macro.

Exercise 2: Improving on Recorded Macros

This exercise shows that when macros are recorded, often more code is generated than necessary. It demonstrates the use of the With statement to précis the code.

  1. Select any cell or block of cells.
  2. Start the macro recorder and call the macro FormatCells. The Relative References setting will not be relevant.
  3. Go to Format > Cells > Font and choose Times New Roman and Red.
    Go to Patterns and choose Yellow.
    Go to Alignment and choose Horizontal, Center
    Go to Number and choose Currency.
  4. Click OK and stop the recorder.
  5. Click the Undo button (or Ctrl+Z) to undo your changes to the worksheet.
  6. Select a block of cells and run the FormatCells macro. Note that it can not be undone! Type in the cells to check the result of the formatting.
  7. Look at the code:

    Sub
    FormatSelection()

    Selection.NumberFormat = “$#,##0.00″

    With Selection

    .HorizontalAlignment = xlCenter

    .VerticalAlignment = xlBottom

    .WrapText = False

    .Orientation = 0

    .ShrinkToFit = False

    .MergeCells = False

    End With

    With
    Selection.Font

    .Name = “Times New Roman”

    .FontStyle = “Regular”

    .Size = 10

    .Strikethrough = False

    .Superscript = False

    .Subscript = False

    .OutlineFont = False

    .Shadow = False

    .Underline = xlUnderlineStyleNone

    .ColorIndex = 3

    End With

    With
    Selection.Interior

    .ColorIndex = 6

    .Pattern = xlSolid

    .PatternColorIndex = xlAutomatic

    End With

    End Sub

     

  8. Note all the extra instructions that have been recorded. Delete lines of code so that only the following remains:

    Sub
    FormatSelection()

    Selection.NumberFormat = “$#,##0.00″

    With
    Selection

    .HorizontalAlignment = xlCenter

    End With

    With
    Selection.Font

    .Name = “Times New Roman”

    .ColorIndex = 3

    End With

    With
    Selection.Interior

    .ColorIndex = 6

    End With

    End Sub

  9. Run the macro to test the edited code. It still works as before.
  10. Now modify the code even further:

Sub
FormatSelection()

With
Selection

.NumberFormat = “$#,##0.00″

.HorizontalAlignment = xlCenter

.Font.Name = “TimesNewRoman”

.Font.ColorIndex = 3

.Interior.ColorIndex = 6

End With

End Sub

  1. Test the macro. Everything still works and the code will run much faster.
  2. Try recording the same macro using toolbar buttons instead of going to the dialog box:
    Change the Font to Times New Roman
    Change the Font Colour to Red
    Change the Fill Color to Yellow
    Click the Center button
    Click the Currency button
  3. Look at the code. You still get lots of stuff that you don’t necessarily want. Excel is recording all the default settings. Most of these are safe to delete.
  4. Experiment with editing directly into the code to change colours, the font, the number format etc.

December 27, 2008 at 3:50 pm Leave a comment

Improving Recorded Macros

The good way to learn the basics of VBA is to record a macro and see how Excel writes its own code. Often, though, recorded macros contain much more code than is necessary. The following exercises demonstrate how you can improve and streamline code that has been produced by a recorded macro.

Exercise 2: Improving on Recorded Macros

This exercise shows that when macros are recorded, often more code is generated than necessary. It demonstrates the use of the With statement to précis the code.

  1. Select any cell or block of cells.
  2. Start the macro recorder and call the macro FormatCells. The Relative References setting will not be relevant.
  3. Go to Format > Cells > Font and choose Times New Roman and Red.
    Go to Patterns and choose Yellow.
    Go to Alignment and choose Horizontal, Center
    Go to Number and choose Currency.
  4. Click OK and stop the recorder.
  5. Click the Undo button (or Ctrl+Z) to undo your changes to the worksheet.
  6. Select a block of cells and run the FormatCells macro. Note that it can not be undone! Type in the cells to check the result of the formatting.
  7. Look at the code:

    Sub
    FormatSelection()

    Selection.NumberFormat = “$#,##0.00″

    With Selection

    .HorizontalAlignment = xlCenter

    .VerticalAlignment = xlBottom

    .WrapText = False

    .Orientation = 0

    .ShrinkToFit = False

    .MergeCells = False

    End With

    With
    Selection.Font

    .Name = “Times New Roman”

    .FontStyle = “Regular”

    .Size = 10

    .Strikethrough = False

    .Superscript = False

    .Subscript = False

    .OutlineFont = False

    .Shadow = False

    .Underline = xlUnderlineStyleNone

    .ColorIndex = 3

    End With

    With
    Selection.Interior

    .ColorIndex = 6

    .Pattern = xlSolid

    .PatternColorIndex = xlAutomatic

    End With

    End Sub

     

  8. Note all the extra instructions that have been recorded. Delete lines of code so that only the following remains:

    Sub
    FormatSelection()

    Selection.NumberFormat = “$#,##0.00″

    With
    Selection

    .HorizontalAlignment = xlCenter

    End With

    With
    Selection.Font

    .Name = “Times New Roman”

    .ColorIndex = 3

    End With

    With
    Selection.Interior

    .ColorIndex = 6

    End With

    End Sub

  9. Run the macro to test the edited code. It still works as before.
  10. Now modify the code even further:

Sub
FormatSelection()

With
Selection

.NumberFormat = “$#,##0.00″

.HorizontalAlignment = xlCenter

.Font.Name = “TimesNewRoman”

.Font.ColorIndex = 3

.Interior.ColorIndex = 6

End With

End Sub

  1. Test the macro. Everything still works and the code will run much faster.
  2. Try recording the same macro using toolbar buttons instead of going to the dialog box:
    Change the Font to Times New Roman
    Change the Font Colour to Red
    Change the Fill Color to Yellow
    Click the Center button
    Click the Currency button
  3. Look at the code. You still get lots of stuff that you don’t necessarily want. Excel is recording all the default settings. Most of these are safe to delete.
  4. Experiment with editing directly into the code to change colours, the font, the number format etc.

December 27, 2008 at 3:35 pm Leave a comment

Older Posts


Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 14 other followers

Blog Stats

  • 78,361 hits

Twitter Updates

Iklan


Follow

Get every new post delivered to your Inbox.