zraptor
asked on
EXLWS.PrintOut problem!!!!!!!!
Hello all,
Im stuck in a pretty bad situation here, I wrote a program that will export data to an excel spreadsheet and then print that sheet without the user ever seeing Excel. When running the program on my computer everything works great but when I install the program on another machine and execute the command the program crashes. Below is a sample of the code im using:
========BEGIN CODE==========
Set appEXL2 = New excel.Application
Set EXLwb2 = appEXL2.Workbooks.Open(Get WinDir & "\Cons Manager\MASTER CONS.xls")
Set EXLws2 = EXLwb2.Worksheets(1)
EXLws2.Visible = xlSheetVisible
With EXLws2
.Cells(8, 6).Value = MDate
.Cells(11, 6).Value = MRoute
.Cells(14, 6).Value = MOrig
.Cells(17, 6).Value = MDest
.Cells(21, 2).Value = MCNUM
End With
EXLws2.PrintOut
========END CODE==========
Any ideas!?!? This one is pretty urgent!
Im stuck in a pretty bad situation here, I wrote a program that will export data to an excel spreadsheet and then print that sheet without the user ever seeing Excel. When running the program on my computer everything works great but when I install the program on another machine and execute the command the program crashes. Below is a sample of the code im using:
========BEGIN CODE==========
Set appEXL2 = New excel.Application
Set EXLwb2 = appEXL2.Workbooks.Open(Get
Set EXLws2 = EXLwb2.Worksheets(1)
EXLws2.Visible = xlSheetVisible
With EXLws2
.Cells(8, 6).Value = MDate
.Cells(11, 6).Value = MRoute
.Cells(14, 6).Value = MOrig
.Cells(17, 6).Value = MDest
.Cells(21, 2).Value = MCNUM
End With
EXLws2.PrintOut
========END CODE==========
Any ideas!?!? This one is pretty urgent!
Hi,
By checking the code in a VB 6 environment, I've modified it, as in the below code, which runs properly. (I have created a button to start the code)
__________________________ __________ __________ ____
Private Sub Command1_Click()
Dim appEXL2 As Object
Dim EXLwb2 As Object
Dim EXLws2 As Object
Set appEXL2 = CreateObject("Excel.Applic ation")
Set EXLwb2 = appEXL2.Workbooks.Open("C: \PrintOutT est.xls")
Set EXLws2 = EXLwb2.Worksheets(1)
' EXLws2.Visible = xlSheetVisible
' The variables were modified for testing purposes
With EXLws2
.Cells(8, 6).Value = "MDate2"
.Cells(11, 6).Value = "MRoute2"
.Cells(14, 6).Value = "MOrig2"
.Cells(17, 6).Value = "MDest2"
.Cells(21, 2).Value = "MCNUM2"
End With
' This will print the worksheet in the default printer
EXLwb2.PrintOut
' Remember to close the file
' As it was modified, will ask for saving
result2 = appEXL2.Workbooks.Close()
End Sub
__________________________ __________ __________ ____
Jose
By checking the code in a VB 6 environment, I've modified it, as in the below code, which runs properly. (I have created a button to start the code)
__________________________
Private Sub Command1_Click()
Dim appEXL2 As Object
Dim EXLwb2 As Object
Dim EXLws2 As Object
Set appEXL2 = CreateObject("Excel.Applic
Set EXLwb2 = appEXL2.Workbooks.Open("C:
Set EXLws2 = EXLwb2.Worksheets(1)
' EXLws2.Visible = xlSheetVisible
' The variables were modified for testing purposes
With EXLws2
.Cells(8, 6).Value = "MDate2"
.Cells(11, 6).Value = "MRoute2"
.Cells(14, 6).Value = "MOrig2"
.Cells(17, 6).Value = "MDest2"
.Cells(21, 2).Value = "MCNUM2"
End With
' This will print the worksheet in the default printer
EXLwb2.PrintOut
' Remember to close the file
' As it was modified, will ask for saving
result2 = appEXL2.Workbooks.Close()
End Sub
__________________________
Jose
ASKER
Will that code still work if I modify it to allow for the user to select a printer to print to?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, The default printer thing was the problem, Thanks a lot for the help!!!!
Sounds the file isn't present and the program crashs due commands to Excel for an unopen file. Or the default printer isn't available.
You may debug it with a step by step execution to discover where the problem occurs. For exemple, by creating a keyboard entry between each statement with a message. Something like "OK, file open", "Worksheet 1 OK", "Visible OK", etc.
Check the file in the new machine, read only? Need macros? Correct path?
Also if the default printer is online and corresponds to the actual printer.
Jose