Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

VB 6 and MS-Word question
Hi,



I need some hints for the following problem.

I have a VB 6 application that needs to write data (text and image) to a
Ms-Word document (template)

So I created a Ms-Word document with some bookmarks. The VB App is able to
write the data to the Ms-Word document and save it with a new doc-name.

But.this works only for one page. How to deal with a multiple page document.
Beforehand I don't know how much pages I need. One page contains a few text
lines and one image.



Can I define the image size ?



A piece of my (test)code.



' Project References = Microsoft Word 11.0 Object Library

Dim WordObj As Word.Application

Dim WordDoc As Word.Document

Dim WordRange As Word.Range

mydate$ = Date

Set WordObj = CreateObject("Word.Application")

Set WordDoc = WordObj.Documents.Open(App.Path & "\report.doc")

WordObj.Visible = True



'Date

Set WordRange = WordDoc.GoTo(What:=wdGoToBookmark, Name:="Date")

WordRange.InsertAfter mydate$ 'inserts the contents



'Photo

Set WordRange = WordDoc.GoTo(What:=wdGoToBookmark, Name:="photo")

WordRange.InlineShapes.AddPicture FileName:= myfile$, LinkToFile _

:=False, SaveWithDocument:=True



Report this thread to moderator Post Follow-up to this message
Old Post
Robert
05-27-05 01:55 PM


Re: VB 6 and MS-Word question
I produced a reporting system using Word where I had a similar problem -
lots of records that had to be formatted in the same way and inserted in to
a document. What I ended up doing was to create two Word documents; the
master document, with all the front matter (front page, table of contents
etc) and a second document that was a template for a record.

When running the report, I load the master document first. Then, for each
record I need to format, load the record template, fill it in, copy it to
the clipboard, paste it in to the master document, then close the template
without saving. I repeat this for each record.

May not be elegant, but it worked for me.

I use the following code to insert and resize images in Word documents:

Set oPicture = oInsertionPoint.InlineShapes.AddPicture(<<FileName>>,
False, True)
oPicture.LockAspectRatio = True
oPicture.Reset
oPicture.ScaleWidth = oPicture.ScaleWidth * (<<Scale percentage>> / 100)
oPicture.ScaleHeight = oPicture.ScaleHeight * (<<Scale percentage>> /
100)


HTH
Steve

"Robert" <Robert@nospam.notvalid> wrote in message
news:b3eb9$429700eb$513b49d4$7259@news.versatel.nl...
> Hi,
>
>
>
> I need some hints for the following problem.
>
> I have a VB 6 application that needs to write data (text and image) to a
> Ms-Word document (template)
>
> So I created a Ms-Word document with some bookmarks. The VB App is able to
> write the data to the Ms-Word document and save it with a new doc-name.
>
> But.this works only for one page. How to deal with a multiple page
> document. Beforehand I don't know how much pages I need. One page contains
> a few text lines and one image.
>
>
>
> Can I define the image size ?
>
>
>
> A piece of my (test)code.
>
>
>
> ' Project References = Microsoft Word 11.0 Object Library
>
>    Dim WordObj As Word.Application
>
>    Dim WordDoc As Word.Document
>
>    Dim WordRange As Word.Range
>
>    mydate$ = Date
>
>    Set WordObj = CreateObject("Word.Application")
>
>    Set WordDoc = WordObj.Documents.Open(App.Path & "\report.doc")
>
>    WordObj.Visible = True
>
>
>
>    'Date
>
>    Set WordRange = WordDoc.GoTo(What:=wdGoToBookmark, Name:="Date")
>
>    WordRange.InsertAfter mydate$ 'inserts the contents
>
>
>
>    'Photo
>
>    Set WordRange = WordDoc.GoTo(What:=wdGoToBookmark, Name:="photo")
>
>    WordRange.InlineShapes.AddPicture FileName:= myfile$, LinkToFile _
>
>        :=False, SaveWithDocument:=True
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Steve Barnett
05-27-05 08:55 PM


Re: VB 6 and MS-Word question
you copy and paste, what if another program uses the clipboard while this is
running?


"Steve Barnett" <noname@nodomain.com> wrote in message
news:OSuYvNrYFHA.3220@TK2MSFTNGP14.phx.gbl...
>I produced a reporting system using Word where I had a similar problem -
>lots of records that had to be formatted in the same way and inserted in to
>a document. What I ended up doing was to create two Word documents; the
>master document, with all the front matter (front page, table of contents
>etc) and a second document that was a template for a record.
>
> When running the report, I load the master document first. Then, for each
> record I need to format, load the record template, fill it in, copy it to
> the clipboard, paste it in to the master document, then close the template
> without saving. I repeat this for each record.
>
> May not be elegant, but it worked for me.
>
> I use the following code to insert and resize images in Word documents:
>
>    Set oPicture = oInsertionPoint.InlineShapes.AddPicture(<<FileName>>,
> False, True)
>    oPicture.LockAspectRatio = True
>    oPicture.Reset
>    oPicture.ScaleWidth = oPicture.ScaleWidth * (<<Scale percentage>> /
> 100)
>    oPicture.ScaleHeight = oPicture.ScaleHeight * (<<Scale percentage>> /
> 100)
>
>
> HTH
> Steve
>
> "Robert" <Robert@nospam.notvalid> wrote in message
> news:b3eb9$429700eb$513b49d4$7259@news.versatel.nl... 
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Bonj
05-28-05 01:55 AM


Re: VB 6 and MS-Word question
I take the chance that nothing will use the clipboard between one statement
and the next. So far, it's worked perfectly well (usually, they're so bored
with the utterly sole destroying "blue bar" they they've gone off to make a
cup of coffee).

I think that, given the amount of time it takes to copy and paste one or two
pages, the risk is acceptable.

Steve

"Bonj" <a@b.com> wrote in message
news:OQZjufvYFHA.3780@tk2msftngp13.phx.gbl...
> you copy and paste, what if another program uses the clipboard while this
> is running?
>
>
> "Steve Barnett" <noname@nodomain.com> wrote in message
> news:OSuYvNrYFHA.3220@TK2MSFTNGP14.phx.gbl... 
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Steve Barnett
05-28-05 01:55 PM


Re: VB 6 and MS-Word question
What about using AutoText. Create a new page after the last line and insert
AutoText (AutoText contains the whole page with bookmarks) ?

Robert



Report this thread to moderator Post Follow-up to this message
Old Post
Robert
05-28-05 08:55 PM


Re: VB 6 and MS-Word question
The way my reporting system was set-up, the user got to define the layout of
the report and could have a different layout for every record if they so
wished.

As designed, there was a master report that defined the general layout of
the document and indicated where I was to insert the records from the
database and there were one or more separate documents that defined how the
record was to be formatted. So, for example, the first couple of records may
have been output as tabular data, the next few included some text and then
there were a few records that included graphs, we might then have some more
tabular stuff. Any one report might consist of any number of templates.

As you can see, the final report could be very complex in it's makeup. What
you then have to play in to the mix is that the people using this system
have very basic word processing skills. Adding AutoText in to the process
would just serve to make it more complex than it needs to be for the user...
and it was ease of use for the user that I was after rather than an elegant
"technical" solution.

We so often forget that people have to use this stuff.

Steve


"Robert" <Robert@nospam.notvalid> wrote in message
news:4277d$4298588d$513b49d4$10535@news.versatel.nl...
> What about using AutoText. Create a new page after the last line and
> insert AutoText (AutoText contains the whole page with bookmarks) ?
>
> Robert
>



Report this thread to moderator Post Follow-up to this message
Old Post
Steve Barnett
05-29-05 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Visual Basic archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:29 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.