PerlIsGood
Programmer
Ok, I've searched both this forum and the VBA forum looking for the right syntax to close an Excel workbook from an Outlook form - so far every solution I've tried fails because Outlook is telling me it doesn't support that method { errrgh }.
Here's what I have which currently works:
The last 4 lines work, but I don't want to shut Excel down when people might be using it for other purposes - I only want to close the workbook that I've modified. I've tried oExcel.Close and oExcel.ActiveWorkbook.Close, but both cause an error.
Any ideas would be greatly appreciated
Here's what I have which currently works:
Code:
Set fso = CreateObject("Scripting.FileSystemObject")
FileLoc = NetPath & FormFiles & "cand_expense.xls"
If fso.FileExists(FileLoc) Then
On Error Resume Next
Set oExcel = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Err.Clear
Set oExcel = CreateObject("Excel.Application")
End If
Else
strErr = FileLoc & " could not be found."
MsgBox (strErr), vbCritical, "Error: File Not Found"
Exit Function
End If
oExcel.Workbooks.Open (FileLoc)
oExcel.Visible = False
varRow = 1
Do While oExcel.Worksheets("Sheet1").Cells(varRow, 1) > ""
If oExcel.Worksheets("Sheet1").Cells(varRow, 1) = txtCandName Then
Exit Do
End If
varRow = varRow + 1
Loop
oExcel.Worksheets("Sheet1").Cells(varRow, 1).Value = txtCandName
oExcel.Worksheets("Sheet1").Cells(varRow, 2).Value = txtAirCost
oExcel.Worksheets("Sheet1").Cells(varRow, 3).Value = txtTrainCost
oExcel.Worksheets("Sheet1").Cells(varRow, 4).Value = txtLimoCost
oExcel.Worksheets("Sheet1").Cells(varRow, 5).Value = txtHotelCost
For Each oWorkbook in oExcel.Workbooks
oWorkbook.Save
Next
oExcel.Quit
Set oExcel = Nothing
End Function
Any ideas would be greatly appreciated