Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShellExucute unable to close program because it wants to save changes

Status
Not open for further replies.

jlkidd

Programmer
Feb 22, 2001
28
0
0
US
I have written a small application to simply open and print an Invoice that is an Excel spreadsheet. I want to never see it happen. I just want to wake up and the invoice be ready. I have successful written a program to accomplish this except that since I have used the Now() function in the spreadsheet the date changes and thus Excel request to know if you want to save changes. I do not. I simply want the program to end without any user interaction. Here is a copy of my code.

Option Explicit

Const SW_SHOWNORMAL = 1
Const SW_SHOWMINIMIZED = 6
Const SW_HIDE = 0
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long




Private Sub Form_Load()

'Call ShellExecute(Me.hWnd, "print", "TheScarms.xls", "", 0, SW_SHOWNORMAL)

Dim retval As Long

retval = ShellExecute(Me.hwnd, "print", "C:\My Documents\NEO INVOICE.xls", "", "C:\My Documents\", 0)


Unload Me

End Sub

Thanks for looking it over.
 
Tried this on my machine (Win95 with Excel 97) and it works
I also used Now() function in WorkSheet


Code:
Option Explicit

Private Sub Form_Load()
  Dim oXL
  Dim oWorkBook
  Dim sFile As String
  
  sFile = "C:\My Documents\Book3.xls"
  
  Set oXL = CreateObject("Excel.Application")
  Set oWorkBook = oXL.Workbooks.Open(sFile)
  With oWorkBook
    .PrintOut
    .Close False
  End With
  Set oWorkBook = Nothing
  oXL.Quit
  Set oXL = Nothing
  Unload Me
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top