Link to home
Create AccountLog in
Avatar of wraith821
wraith821

asked on

Excel Hangs when saving worksheet from .dll

Hi Experts.
Here's one thats got me stumped.

I have created a .dll that contains a class that opens, saves, closes excel. The code works on all my other machines except the server i need it to run on. The Server is 2003 all the other machines are XP Pro/WinNT 2K. When the program is executed, it never returns an error other than:

>> Faulting application wscript.exe, version 5.6.0.8827, faulting module unknown, version 0.0.0.0, fault address 0x00000000.

Here is how this is setup.

I have 2 vbs scripts. 1 runs a copy of the code that is in the dll (it works), the other references the .dll and calls the Open Save Close Functions in the .dll (This one hangs on the Save Function.)

'Code for Script 1:
'--------------------------------
msgbox "Opening Excel"
Dim oExcelApp
Set oExcelApp = CreateObject("EXCEL.APPLICATION")
oExcelApp.Visible = False
oExcelApp.AlertBeforeOverwriting = False
oExcelApp.DisplayAlerts = False
msgbox "adding workbook"
oExcelApp.Workbooks.Add
oExcelApp.Worksheets("Sheet2").Delete
oExcelApp.Worksheets("Sheet3").Delete
Set oWs = oExcelApp.ActiveSheet
Set oWb = oExcelApp.ActiveWorkbook
msgbox "Editing Worksheet"
With oWs
    .Range("A:A").ColumnWidth = 10.86
    .Range("B:B").ColumnWidth = 18.14
    .Range("C:C").ColumnWidth = 8.43
    .Range("D:D").ColumnWidth = 9.43
    .Range("E:E").ColumnWidth = 8.57
    .Range("F:F").ColumnWidth = 8.57
    .Range("G:G").ColumnWidth = 9.43
'    .Range("H:H").ColumnWidth = 10.43
'    .Range("I:I").ColumnWidth = 10.43
'    .Range("J:J").ColumnWidth = 13.43
    .Name = "Sheet 1"
    .Cells(1, 1).Value = "'Coname " 
    .Cells(2, 1).Value = "'SSN"
    .Cells(2, 2).Value = "'NAME"
    .Cells(2, 3).Value = "'TYPE"
'    .Cells(2, 4).Value = "'STUDENTS_NAME"
'    .Cells(2, 5).Value = "'STUDENT_SSN"
'    .Cells(2, 6).Value = "'DISB_NO"
    .Cells(2, 4).Value = "'DISB_AMT"
    .Cells(2, 5).Value = "'GNTE_FEE"
    .Cells(2, 6).Value = "'ORIG_FEE"
    .Cells(2, 7).Value = "'NET_AMT"
End With
msgbox "saving xls"
 ows.saveas "c:\test.xls"
closeexcel
msgbox "Done"


Sub CloseExcel()
    ' Terminate and release the Excel objects.

    oExcelApp.Quit
   
End Sub


'Code for Script 2
'-----------------------------------------
Dim otm
set otm = createobject("trafficmonitor.clsExcel")
msgbox "opening Excel"
otm.openexcel
msgbox "Saving Excel Workbook"
otm.saveexcel "c:\test.xls" <---------{HANGS HERE}
msgbox "Closing Excel"
otm.closeexcel
msgbox "Done"

once the application is hung. I have to go into task manager and end excel. THe code in Script 1 is the same code as in the .dll {clsExcel}

Good Luck....
I hope you can Help
Avatar of Leo Eikelman
Leo Eikelman

try saving it to a sub folder on the c:\ driver rather then on the root


see if that works,

Leo
Also, have you tried increasing the Request timeout on the server to see if it is still processing or if it just simply crashed and not exiting?

there was also some issue I dug up with saving excel sheets with IncludeHeaders set.  I don't know if u are using this functionality or not.

Also, doing a bit more reading I found that this may infact be a bug.

Make sure you have the latest versions installed.

Cheers,

Leo

Avatar of wraith821

ASKER

This is a vb application not a web app. there are no includes and it running under an account with administrative rights.
ASKER CERTIFIED SOLUTION
Avatar of Leo Eikelman
Leo Eikelman

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
That didn't work. something is preventing Excel from saving at all.
run from the .dll that is.
Well, for all you people wondering... It was my installation of VB6. when the .dll was compiled on my new machine with a new install of vb6, it just didn't work. i have since found other quirks with other compiled exe's and .dlls compiled on this new machine. I recompiled the .dll on my old machine where it was originally created and it works just fine. So.. even though you didn't help me, i'm going to give leikelman all 500 points just because he tried when noone else would.