?
Solved

Printing a word document generated from VB

Posted on 2002-07-07
4
Medium Priority
?
763 Views
Last Modified: 2007-12-19
i've generated a word document from VB with Custom paper size 10" X 12".(we have a preprinted paper format of size 10" X 12").But while printing from word its taking default paper source as Letter which is 8.5" X 11".so i dont get page break properly  while printing .(although it leaves page break properly in the word document.)how to solve this problem?

i've already specified as

Dim objword As New Word.Application
    Dim objTargetDoc As Word.Document
    Set objTargetDoc = objword.Documents.Open("....")
   
    Set objRange = objTargetDoc.Range( _
    Start:=objTargetDoc.Paragraphs(1).Range.Start, _
    End:=objTargetDoc.Paragraphs(objTargetDoc.Paragraphs.Count).Range.End)
    objRange.Select
    objRange.Style = -1
    objTargetDoc.PageSetup.PaperSize = wdPaperCustom

    objTargetDoc.PageSetup.PageWidth = 720    objTargetDoc.PageSetup.PageHeight = 864

is it not 1 inch  = 72 pts
0
Comment
Question by:vaishnavi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 200 total points
ID: 7135058
Hi vaishnavi,

you can try something like this

Sub SetPrintProps()
  With objword.ActiveDocument.PageSetup
    .PageWidth = InchesToPoints(10)
    .PageHeight = InchesToPoints(12)
  End With
End Sub

HAGD:O)Bruintje
0
 
LVL 1

Expert Comment

by:advapp
ID: 7139054
What you have looked like it should work so I stuck in the following lines into an existing project I have that does some word manipulation:

    Set objDoc = InitWordDoc(objWord)
    ...
    objDoc.PageSetup.PaperSize = wdPaperCustom
    objDoc.PageSetup.PageHeight = objDoc.Application.InchesToPoints(10)
    objDoc.PageSetup.PageWidth = objDoc.Application.InchesToPoints(12)

and it appeared to work fine for me.  (The InitWordDoc proc just creates the document and sets the margins to 1" around.)

Of course, I do not have the 10x12 paper so it informed me it was outside the boundaries and asked whether to continue, to which I responded "yes".  But otherwise it worked.

I'd check what state the document is in by doing a print-preview and/or making Word visible to examine the document state.  I can help you with this if you need guidance on how to do it.

NOTE:
By the way, I think you can replace all the lines around

   Set objRange = objTargetDoc.Range( _
   Start:=objTargetDoc.Paragraphs(1).Range.Start, _
   End:=objTargetDoc.Paragraphs(objTargetDoc.Paragraphs.Count).Range.End)
   objRange.Select
   objRange.Style = -1

with:

   objTargetDoc.Content.Select
   objTargetDoc.Content.Style = -1

or you can always set objRange to objTargetDoc.Content if you need an explicit reference to that content range.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7990819
Hi vaishnavi,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept bruintje's comment(s) as an answer.

vaishnavi, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 8053128
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question