-
May 22nd, 2009, 06:36 PM
#1
Thread Starter
Member
printing specific page(.doc, .pdf , .ppt, .xls) using vb6
hi., im newbie here in vbforums. im having problem printing specific page of my documents using vb6 such as .doc, .ppt,.pdf,.xls documents., i can print those document, its just that , it prints all the pages., is it possible to print documents with specific page or specific range of pages. im using vb6 program.,
this is my code in printing my document files:
Const SW_SHOWNORMAL = 1
Option Explicit
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 Command4_Click()
Dim PrintIt As Long
PrintIt = ShellExecute(Me.hwnd, "print", "C:\My Documents\MyDoc.Doc", "", "", SW_SHOWNORMAL)
End Sub
-
May 22nd, 2009, 11:24 PM
#2
Re: printing specific page(.doc, .pdf , .ppt, .xls) using vb6
it depends on the application you are calling (the default for the file type), whether it has provision in command line to set pages, as a general rule, no
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 23rd, 2009, 09:28 AM
#3
Thread Starter
Member
Re: printing specific page(.doc, .pdf , .ppt, .xls) using vb6
sir what am i actually calling application is only MS WORD 2007/2003, MS EXCELL 2007/2003, MS POWERPOINT 2007/2003 , AND ADOBE ACROBAT8/9.,
can i still specify the page that im printing?
-
May 23rd, 2009, 05:52 PM
#4
Re: printing specific page(.doc, .pdf , .ppt, .xls) using vb6
not unless they have that option in their command line arguments,
the other option is to automate the programs, rather than using shellexecute
this means your code will open the program, open the file, then you can change any printer options, normally in pagesetup, then print the document, close the document, then quit the application
this will only work if the application you want to automate is installed on the computer
using shellexecute to print a .doc will use word, but if word is not installed then it will use wordpad to print, if you automate word to print .doc. nothing will work if some version of word not installed,
if you use late binding, you can use whatever version of word is installed as long as your code does not call some method that does not exist in a particular version
same applies to all msoffice applications
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 23rd, 2009, 10:25 PM
#5
Thread Starter
Member
Re: printing specific page(.doc, .pdf , .ppt, .xls) using vb6
sir what do you mean by command line arguements? do you mean by that is making a ms word object llibrary as a reference?
sir i explore the ms word library and i found this:
Word.ActiveDocument.PrintOut
and has a function that its specifies the range of page. but i cant make it worked.,
-
May 24th, 2009, 01:12 AM
#6
Re: printing specific page(.doc, .pdf , .ppt, .xls) using vb6
commandline arguments are like
word /p somefile.doc
word will print somefile (needs full path)
this is similar to how sellexecute works
check out the faq at in the top posts on office development forum for tutorial on automating office applications
Last edited by westconn1; May 24th, 2009 at 01:17 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
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
|