Solved

Printing a word document generated from VB

Posted on 2002-07-07
4
752 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

728 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

9 Experts available now in Live!

Get 1:1 Help Now