Solved

Printing a word document generated from VB

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

688 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