Advertisement
Advertisement
| 06.08.2008 at 02:07PM PDT, ID: 23467622 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: |
Private Sub lblExportToExcel_Click()
'Exports the Contract Details table to an Excel file.
'Microsoft Excel x.x Object Library is required for this method.
'If errors occur, please check References package via Tools->References.
Dim strExcelFile As Variant 'Excel file name specified by user via Save As dialouge
Dim xlApp As Object 'Excel application instance
Dim varTemp As Variant 'Dummy variable to dump data
'See if an instance of Excel is already running.
'If not, create an Excel application instance
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err <> 0 Then
Err.Clear
Set xlApp = CreateObject("Excel.Application")
End If
On Error GoTo ErrorHandler
RetrySave:
'Asks the user to select the file name and location.
strExcelFile = xlApp.GetSaveAsFilename("Export.xls", _
fileFilter:="Microsoft Excel Workbook (*.xls), *.xls")
'Check to see if an incorrect filename was specified by user, and proceed only when no error is found.
If strExcelFile <> False Then
'User enters a correct filename.
If Dir(strExcelFile) <> "" Then 'File already exists
'Overwrite?
If MsgBox("Another file with the same name already exists in the seleted location. Overwrite?", _
vbQuestion + vbYesNo, "File Already Exists") = vbNo Then
GoTo RetrySave
End If
End If
'Export into an XLS file. (This is working)
varTemp = Me.objXLContractYears.Export(strExcelFile, 0)
'Test if I can access OWC spreadsheet created from the form. (no other specific purpose.. this is just to see whether i can access it or not)
varTemp = Me.objXLContractYears.Worksheets(1)
If MsgBox("Contract details have been exported into an Excel file successfully." & vbNewLine & vbNewLine _
& "Saved as: " & vbNewLine & strExcelFile & vbNewLine & vbNewLine & _
"Would you like to open this file in Excel?", vbYesNo + vbInformation, "Excel Export Successful") _
= vbYes Then
xlApp.Visible = True
xlApp.Workbooks.Open FileName:=strExcelFile
End If
Else
If MsgBox("An incorrect filename was entered, or File Save was cancelled." & vbNewLine & _
"Please try again, or click Cancel to return to the original window.", _
vbRetryCancel + vbCritical, "Excel Export Error") = vbRetry Then
GoTo RetrySave
Else
End
End If
End If
If xlApp.Visible = False Then
xlApp.Quit
Set xlApp = Nothing
End If
Exit Sub
ErrorHandler:
MsgBox "An error has occured in this application. Please review the message below." & vbNewLine & vbNewLine & _
"Error: [" & Err.Number & "] " & Err.Description, Buttons:=vbCritical, Title:="Error"
End Sub
|