| Public Function GridExport(GridToExport _ As Object, FileName As String, Optional _ Delimiter As Variant, Optional _ EncloseStrings As Variant) As Boolean '************************************ 'Purpose: Export contents of Grid Control to 'a test file 'Parameters: GridToExport: Grid Object 'File Name: File Name to write to 'Delimiter: Value Delimiter (optional), default to vbTab 'EncloseStrings (Optional): String identfier, defaults to none ("") 'Returns: True if succesful, false otherwise '************************************ On Error GoTo ErrHandler Dim iNumRows As Integer Dim iNumCols As Integer Dim iFileNumber As Integer If IsMissing(Delimiter) Then Delimiter = vbTab End If If IsMissing(EncloseStrings) Then EncloseStrings = "" End If iFileNumber = FreeFile Open FileName For Output As #iFileNumber For iNumRows = 0 To _ GridToExport.Rows - 1 GridToExport.Row = iNumRows For iNumCols = 0 To _ GridToExport.Cols - 1 GridToExport.col = iNumCols 'if it isn't the first column, 'put a delimiter before the value If iNumCols > 0 Then Print #iFileNumber, Delimiter; End If Print #iFileNumber, EncloseStrings & _ GridToExport.Text & EncloseStrings; Next iNumCols Print #iFileNumber, "" Next iNumRows GridExport = True ErrHandler: If iFileNumber > 0 Then Close #iFileNumber End Function |
Save Contents of a Grid Control to a Text File |
Express News India | Freelance ecommerce web development India