Solved

Printing a word document generated from VB

Posted on 2002-07-07
4
760 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 50 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

738 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