W
Woody
i have a vb6 program that runs great from teh ide but errors with
application has disconnected from objects when i run it standalone.
I was pointed in this direction so im hoping someone can help me resolve
this please.
The code dealing with excel:
___________________________________________________________
Dim exlApp As Excel.Application
Dim exlBook As Excel.Workbook
Dim exlSheet As Excel.Worksheet
'----------------------------------------------------------------
' Get Excel if it's running
Set exlApp = GetObject(, "Excel.Application")
If Err <> 0 Then
'Excel wasn't running, start it from code
Set exlApp = CreateObject("Excel.Application")
End If
' remove old file, create new spreadsheet from existing
Kill App.Path & "\" & newDocName & ".xls"
Set exlBook = exlApp.Workbooks.Open(App.Path & "\" &
"ProtoLetters.xls", False, True)
exlBook.SaveAs FileName:=App.Path & "\" & newDocName & ".xls"
Set exlSheet = exlBook.Worksheets("Sheet1")
dblCount = dblCount + 1
With exlSheet
.Activate
.Cells(dblCount, 1) = "Value 1"
.Cells(dblCount, 2) = "Value 2"
.Cells(dblCount, 3) = "Value 3"
.Cells(dblCount, 4) = "Value 4"
.Cells(dblCount, 5) = "Value 5"
If dblCount = 1 then
.Cells(dblCount, 6) = "N/A"
.Cells(dblCount, 7) = "N/A"
End If
End With
' finish spread sheet and end excel
' borders for data cells
With exlSheet
.Activate
.Range(.Cells(2, 1), .Cells(dblCount, 15)).Borders.LineStyle =
xlContinuous
.Range(.Cells(2, 1), .Cells(dblCount, 15)).Borders.ColorIndex = 1
.Range(.Cells(2, 1), .Cells(dblCount, 15)).Borders.Weight = xlThin
.Range(.Cells(1, 1), .Cells(dblCount, 15)).Columns.AutoFit
.PageSetup.LeftHeader = "Printed on &D"
.PageSetup.CenterHeader = "&B Applicants"
.PageSetup.RightHeader = "Scheduled"
.PageSetup.LeftFooter = "Page &P of &N"
.PageSetup.CenterFooter = "&B &I My Company"
.PageSetup.RightFooter = "&B Company Confidential Information"
.PageSetup.Orientation = xlLandscape
End With
' save spreadsheet, close it, end Excel
exlApp.ActiveWorkbook.Save
exlApp.ActiveWorkbook.Close
exlApp.Quit
___________________________________________________________
Thanks in advance for your time and consideration
sincerely
Woody
I am not responsible for anything you may see with my name attached to
it, i think.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
application has disconnected from objects when i run it standalone.
I was pointed in this direction so im hoping someone can help me resolve
this please.
The code dealing with excel:
___________________________________________________________
Dim exlApp As Excel.Application
Dim exlBook As Excel.Workbook
Dim exlSheet As Excel.Worksheet
'----------------------------------------------------------------
' Get Excel if it's running
Set exlApp = GetObject(, "Excel.Application")
If Err <> 0 Then
'Excel wasn't running, start it from code
Set exlApp = CreateObject("Excel.Application")
End If
' remove old file, create new spreadsheet from existing
Kill App.Path & "\" & newDocName & ".xls"
Set exlBook = exlApp.Workbooks.Open(App.Path & "\" &
"ProtoLetters.xls", False, True)
exlBook.SaveAs FileName:=App.Path & "\" & newDocName & ".xls"
Set exlSheet = exlBook.Worksheets("Sheet1")
dblCount = dblCount + 1
With exlSheet
.Activate
.Cells(dblCount, 1) = "Value 1"
.Cells(dblCount, 2) = "Value 2"
.Cells(dblCount, 3) = "Value 3"
.Cells(dblCount, 4) = "Value 4"
.Cells(dblCount, 5) = "Value 5"
If dblCount = 1 then
.Cells(dblCount, 6) = "N/A"
.Cells(dblCount, 7) = "N/A"
End If
End With
' finish spread sheet and end excel
' borders for data cells
With exlSheet
.Activate
.Range(.Cells(2, 1), .Cells(dblCount, 15)).Borders.LineStyle =
xlContinuous
.Range(.Cells(2, 1), .Cells(dblCount, 15)).Borders.ColorIndex = 1
.Range(.Cells(2, 1), .Cells(dblCount, 15)).Borders.Weight = xlThin
.Range(.Cells(1, 1), .Cells(dblCount, 15)).Columns.AutoFit
.PageSetup.LeftHeader = "Printed on &D"
.PageSetup.CenterHeader = "&B Applicants"
.PageSetup.RightHeader = "Scheduled"
.PageSetup.LeftFooter = "Page &P of &N"
.PageSetup.CenterFooter = "&B &I My Company"
.PageSetup.RightFooter = "&B Company Confidential Information"
.PageSetup.Orientation = xlLandscape
End With
' save spreadsheet, close it, end Excel
exlApp.ActiveWorkbook.Save
exlApp.ActiveWorkbook.Close
exlApp.Quit
___________________________________________________________
Thanks in advance for your time and consideration
sincerely
Woody
I am not responsible for anything you may see with my name attached to
it, i think.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!