Sunday, June 17, 2012

Contoh Menggunakan CommonDialog Open Save As

'Contoh untuk CommonDialog Open
Private Sub Command1_Click()

On Error GoTo ErrHandler

Dim strPath As String

With CommonDialog1
.CancelError = True
.Flags = cdlOFNHideReadOnly
.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
.FilterIndex = 2
.DialogTitle = "Open File"
.ShowOpen
strPath = .FileName
End With
'Code selanjutnya
Exit Sub

ErrHandler:

Exit Sub

End Sub

'Contoh untuk CommonDialog Save As
Private Sub Command2_Click()

On Error GoTo ErrHandler

Dim strPath As String

With CommonDialog1
.CancelError = True
.Flags = cdlOFNHideReadOnly
.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
.FilterIndex = 2
.DialogTitle = "Save As"
.ShowSave
strPath = .FileName
End With
'Code selanjutnya
Exit Sub

ErrHandler:

Exit Sub
End Sub

'Contoh untuk CommonDialog Save
Private Sub Command3_Click()

On Error GoTo ErrHandler

Dim strPath As String

With CommonDialog1
.CancelError = True
.Flags = cdlOFNHideReadOnly
.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
.FilterIndex = 2
.DialogTitle = "Save"
.ShowSave
strPath = .FileName
End With
'Code selanjutnya
Exit Sub

ErrHandler:

Exit Sub
End Sub