I added this code to a an ASP page to print a gridview in Microsoft Excel. This page is a weekly work schedule for our company's intranet. The code works on a majority(80%) of the workstations in our business. On those machines that stop in mid script. The excel object is opened and visible; however the script stops executing at the line:
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML <----- Script stops executing at this point
The whole code:
Sub exportbutton_onclick
Const xlCellTypeLastCell = 11
dim sHTML, oExcel, oBook, LastRowWithData, Row
Dim ExcelLastCell, LastRow
If Err.Number > 0 Then
Call ErrorProc
End If
sHTML = document.all.item("dgWeekly_Plan").outerhtml
set oExcel = CreateObject("Excel.Application")
set oBook = oExcel.Workbooks.Add
oExcel.Visible = true
oExcel.UserControl = true
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML <----- Script stops executing at this point
oBook.HTMLProject.Refreshdocument
oExcel.ActiveWorkBook.ActiveSheet.Range("A2").Enti reColumn.Hidden = True
oExcel.ActiveWorkBook.ActiveSheet.Range("H2").Enti reColumn.Hidden = True
oExcel.ActiveWorkBook.ActiveSheet.PageSetUp.Orient ation = 2
oExcel.ActiveWorkBook.Activesheet.PageSetUp.LeftMa rgin = oExcel.Application.InchesToPoints(0.25)
oExcel.ActiveWorkBook.Activesheet.PageSetUp.RightM argin = oExcel.Application.InchesToPoints(0.25)
oExcel.ActiveWorkBook.Activesheet.PageSetUp.TopMar gin = oExcel.Application.InchesToPoints(0.5)
oExcel.ActiveWorkBook.Activesheet.PageSetUp.Bottom Margin = oExcel.Application.InchesToPoints(0.5)
oExcel.ActiveWorkBook.ActiveSheet.PageSetUp.Zoom = False
oExcel.ActiveWorkBook.ActiveSheet.PageSetUp.FitToP agesWide = 1
oExcel.ActiveWorkBook.ActiveSheet.PageSetUp.FitToP agesTall = 1
x = oExcel.ActiveWorkBook.ActiveSheet.UsedRange.Rows.C ount
if x < 20 then
h = 30
f = 10
elseif x > 20 and x < 30 then
h = 25
f = 10
else
h = 17
f = 7
end if
for x = 4 to x - 1
sRow = "A" & x
oExcel.ActiveWorkBook.ActiveSheet.Range(sRow).RowH eight = h
next
oExcel.ActiveWorkBook.ActiveSheet.Columns("A:H").F ont.Size = f
end sub
Sub ErrorProc
msgbox err.description
End Sub
Additionally on several machines the script use to work and now stops in mid script. I do not get an error message. The script simply stops executing.
Thank you in advance for your help