|
-
Oct 22nd, 2002, 09:08 PM
#1
Thread Starter
Member
Word does not print
Hello to all,
word2000 and vb6
When I run this in debug mode, I get me letters.
If I run this in RUNTIME mode, I get no letters.
here is where I think it does not work
objWordDocuments.Application.PrintOut
Do anyone have any idea what is going on here.
I spend a week on this but could not figured it out.
thanks a bunch.
Private Sub CmdCustomerLetter_Click()
call InitilizeWord
call CheckedBoxSelected
end sub
Private Sub InitilizeWord()
'CREATE MS WORD APPLICATION OBJECT.
If TypeName(objWordApplication) = "Application" Then
Set objWordApplication = GetObject(, "Word.Application")
Else
Set objWordApplication = CreateObject("Word.Application")
End If
Set objWordDocuments = objWordApplication.Documents
Exit Sub
end sub
Private Sub CheckedBoxSelected()
Dim k As Integer
If Me.LvwCust.ListItems.Count > 1 Then
For k = 1 To Me.LvwCust.ListItems.Count
If Me.LvwCust.ListItems.Item(k).Checked Then
Call GetBkMark(k)
End If
Next k
End If
End Sub
Private Sub GetBkMark(ByVal SelItemIndex As Integer)
'*************************************************************************************************** *****************
Dim strPathName As String
Dim strFileName As String
Dim j As Integer
Dim objTemplate As Word.Document
Dim k As Integer
strPathName = App.Path & "\"
strFileName = "Customer.dot"
Set objWordDocuments = objWordApplication.Documents
'Set objTemplate = objWordDocuments.Add(strPathName & strFileName, True, wdNewBlankDocument, True)
For k = 1 To Me.LvwCust.ListItems.Count
If k = SelItemIndex Then
Set objTemplate = objWordDocuments.Add(strPathName & strFileName, True, wdNewBlankDocument, True)
With objTemplate
If .Bookmarks.Exists("CustName") Then
.Bookmarks("CustName").Range.text =Trim(Me.LvwCust.ListItems.Item(k).SubItems(2)) & " " & Trim(Me.LvwCust.ListItems.Item(k).SubItems(1)))
End If
'ADDRESS
If .Bookmarks.Exists("Address") Then
.Bookmarks("Address").Range.text = Trim(Me.LvwCust.ListItems.Item(k).SubItems(5)))
End If
objWordDocuments.Application.PrintOut
End With
End If
Next k
End Sub
-
Oct 22nd, 2002, 09:13 PM
#2
PowerPoster
Well
Not a reply, just to VB things better...
VB Code:
Private Sub CmdCustomerLetter_Click()
call InitilizeWord
call CheckedBoxSelected
end sub
Private Sub InitilizeWord()
'CREATE MS WORD APPLICATION OBJECT.
If TypeName(objWordApplication) = "Application" Then
Set objWordApplication = GetObject(, "Word.Application")
Else
Set objWordApplication = CreateObject("Word.Application")
End If
Set objWordDocuments = objWordApplication.Documents
Exit Sub
end sub
Private Sub CheckedBoxSelected()
Dim k As Integer
If Me.LvwCust.ListItems.Count > 1 Then
For k = 1 To Me.LvwCust.ListItems.Count
If Me.LvwCust.ListItems.Item(k).Checked Then
Call GetBkMark(k)
End If
Next k
End If
End Sub
Private Sub GetBkMark(ByVal SelItemIndex As Integer)
'***************************************************************************************************
*****************
Dim strPathName As String
Dim strFileName As String
Dim j As Integer
Dim objTemplate As Word.Document
Dim k As Integer
strPathName = App.Path & "\"
strFileName = "Customer.dot"
Set objWordDocuments = objWordApplication.Documents
'Set objTemplate = objWordDocuments.Add(strPathName & strFileName, True, wdNewBlankDocument, True)
For k = 1 To Me.LvwCust.ListItems.Count
If k = SelItemIndex Then
Set objTemplate = objWordDocuments.Add(strPathName & strFileName, True, wdNewBlankDocument, True)
With objTemplate
If .Bookmarks.Exists("CustName") Then
.Bookmarks("CustName").Range.text =Trim(Me.LvwCust.ListItems.Item(k).SubItems(2)) & " " & Trim(Me.LvwCust.ListItems.Item(k).SubItems(1)))
End If
'ADDRESS
If .Bookmarks.Exists("Address") Then
.Bookmarks("Address").Range.text = Trim(Me.LvwCust.ListItems.Item(k).SubItems(5)))
End If
objWordDocuments.Application.PrintOut
End With
End If
Next k
End Sub
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Oct 23rd, 2002, 03:50 AM
#3
Frenzied Member
Every time I have seen someone use the .PrintOut command with word, I have seen more parameters. For example:
Obj.PrintOut Range:=wdPrintFromTo, From:=”1”. To:=”3”
Obj.PrintOut copies:=1, collate:=True, Background:=False
In these cases OBJ is the DOCUMENT, not the collection of documents or the application. I.e. it should be ObjTemplate in your example.
-
Oct 23rd, 2002, 06:01 PM
#4
Thread Starter
Member
Hi JordanChris,
I have an error here on this line From:=”1”. To:=”3”
what does it relally mean.
Obj.PrintOut Range:=wdPrintFromTo, From:=”1”. To:=”3”
Also, is there a way I can output each document to the screen for user to edit the document if they wanted to and then print them out.
thanks
-
Oct 24th, 2002, 02:47 AM
#5
Frenzied Member
Sorry. That code was for use in the VBA of Word, rather than in VB calling word - slightly different syntax.
Yes, you can show the document to the user - but you might not then be able to prnit t automatically, as you wont know when the user has finished looking at it and its ready to print.
Take a look at the
<Object>.Visible = True
property. This might need to be set on the application (objWordApplication) or on the document (objTemplate).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|