Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Printing document from code

I have a code in excel that has the user pick a document, then certain
lines are omitted and a word doc. is created. Is there a way to just
have it print the created word document after it has been made? It
does not need to be saved, just printed. Here is the code I have:

Private Sub CommandButton1_Click()
filopn1 = Application.GetOpenFilename("Text Files (*.prg), *.prg*")
If filopn1 = "" Then
MsgBox "Please select a file"
Exit Sub
End If

If UCase(Right(filopn1, 3)) < "PRG" Then
MsgBox "This app only good for program files"
Exit Sub
End If

TextBox1.Text = filopn1
Call Make_Sections(filopn1)

End Sub
Sub Make_Sections(MyFile As Variant)
Dim OutputFile As String
Dim count As Integer
Dim LineArray() As String
Dim MyLine As String
Dim arrNum As Long

On Error GoTo MyErrorHandler:

ReDim LineArray(10000) 'This redimensions this array...I
am assuming there is less than
'10000 lines between tool sets.
OutputFile = Mid$(CStr(MyFile), 1, Len(MyFile) - 3) & "doc"
Open MyFile For Input As #1
Open OutputFile For Output As #2

'This first loop gets you past the header info before the first
parentheses (
Line Input #1, MyLine ' Initialize a line
While InStr(1, MyLine, "(") = 0 'Until you find a ( just keep
kicking out lines)
Print #2, MyLine
Line Input #1, MyLine
Wend

arrNum = 1
While Not EOF(1)
If InStr(1, MyLine, "(") < 0 Then 'The first instance may or may
not have lines
Print #2, MyLine 'above it...this should be o.k.
For i = 1 To 30 'Print 30 lines after the (
Line Input #1, MyLine
Print #2, MyLine
Next i

For i = 1 To 6
Print #2,
Next i

Line Input #1, MyLine


Do Until InStr(1, MyLine, "(") < 0 'Until find another (, read
lines into array
LineArray(arrNum) = MyLine
arrNum = arrNum + 1
Line Input #1, MyLine
Loop
If InStr(1, MyLine, "(") < 0 Then
For i = 20 To 1 Step -1
Print #2, LineArray(arrNum - i)
Next i
End If
ReDim LineArray(10000) 'This just empties out the
lines in the array
arrNum = 1
End If
Wend

Close #1
Close #2
UserForm1.Hide

MyErrorHandler:
If Err.Number = 62 Then
Close #1
Close #2
UserForm1.Hide
Exit Sub

End If

End Sub

Essentially, the document could be hundreds of pages long with twenty
sections. This program keeps the first thirty lines and the last ten
lines of each section and makes the document 20 pages long, one page
per section. Each section starts with a "(" and after the first thirty
lines, there is no "(" until the next section. I would just like the
document that is created to be printed automatically.

Any help would be appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Printing document from code

You could ShellExecute with the "print" operation, then Kill the file.
Or use automation:
Dim MyWord As Word.Application
Set MyWord=New Word.Application
....Open your doc
....Print
....Close
....delete

NickHK

wrote in message
oups.com...
I have a code in excel that has the user pick a document, then certain
lines are omitted and a word doc. is created. Is there a way to just
have it print the created word document after it has been made? It
does not need to be saved, just printed. Here is the code I have:

Private Sub CommandButton1_Click()
filopn1 = Application.GetOpenFilename("Text Files (*.prg), *.prg*")
If filopn1 = "" Then
MsgBox "Please select a file"
Exit Sub
End If

If UCase(Right(filopn1, 3)) < "PRG" Then
MsgBox "This app only good for program files"
Exit Sub
End If

TextBox1.Text = filopn1
Call Make_Sections(filopn1)

End Sub
Sub Make_Sections(MyFile As Variant)
Dim OutputFile As String
Dim count As Integer
Dim LineArray() As String
Dim MyLine As String
Dim arrNum As Long

On Error GoTo MyErrorHandler:

ReDim LineArray(10000) 'This redimensions this array...I
am assuming there is less than
'10000 lines between tool sets.
OutputFile = Mid$(CStr(MyFile), 1, Len(MyFile) - 3) & "doc"
Open MyFile For Input As #1
Open OutputFile For Output As #2

'This first loop gets you past the header info before the first
parentheses (
Line Input #1, MyLine ' Initialize a line
While InStr(1, MyLine, "(") = 0 'Until you find a ( just keep
kicking out lines)
Print #2, MyLine
Line Input #1, MyLine
Wend

arrNum = 1
While Not EOF(1)
If InStr(1, MyLine, "(") < 0 Then 'The first instance may or may
not have lines
Print #2, MyLine 'above it...this should be o.k.
For i = 1 To 30 'Print 30 lines after the (
Line Input #1, MyLine
Print #2, MyLine
Next i

For i = 1 To 6
Print #2,
Next i

Line Input #1, MyLine


Do Until InStr(1, MyLine, "(") < 0 'Until find another (, read
lines into array
LineArray(arrNum) = MyLine
arrNum = arrNum + 1
Line Input #1, MyLine
Loop
If InStr(1, MyLine, "(") < 0 Then
For i = 20 To 1 Step -1
Print #2, LineArray(arrNum - i)
Next i
End If
ReDim LineArray(10000) 'This just empties out the
lines in the array
arrNum = 1
End If
Wend

Close #1
Close #2
UserForm1.Hide

MyErrorHandler:
If Err.Number = 62 Then
Close #1
Close #2
UserForm1.Hide
Exit Sub

End If

End Sub

Essentially, the document could be hundreds of pages long with twenty
sections. This program keeps the first thirty lines and the last ten
lines of each section and makes the document 20 pages long, one page
per section. Each section starts with a "(" and after the first thirty
lines, there is no "(" until the next section. I would just like the
document that is created to be printed automatically.

Any help would be appreciated.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003 printing problem--printing 1 document on 2 pages Bons Excel Discussion (Misc queries) 0 December 24th 09 04:15 PM
About printing a document FiluDlidu Excel Discussion (Misc queries) 3 February 3rd 09 12:14 AM
Not printing whole document syssupspe Excel Discussion (Misc queries) 2 April 9th 07 01:02 PM
Need help with printing Excel document jody mullis via OfficeKB.com New Users to Excel 6 June 27th 05 04:32 AM
Printing and Document Name Wayne Blosat Excel Programming 1 August 23rd 03 06:45 PM


All times are GMT +1. The time now is 11:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"