Solved

Printing a word document generated from VB

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now