Home All Groups Group Topic Archive Search About

VB 6 and MS-Word question

Author
27 May 2005 11:13 AM
Robert
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 _

Show quoteHide quote
        :=False, SaveWithDocument:=True

Author
27 May 2005 11:58 AM
Steve Barnett
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

Show quoteHide quote
"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
>
>
Author
27 May 2005 8:09 PM
Bonj
you copy and paste, what if another program uses the clipboard while this is
running?


Show quoteHide quote
"Steve Barnett" <non***@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...
>> 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
>>
>>
>
>
Author
28 May 2005 10:41 AM
Steve Barnett
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

Show quoteHide quote
"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" <non***@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...
>>> 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
>>>
>>>
>>
>>
>
>
Author
28 May 2005 11:39 AM
Robert
What about using AutoText. Create a new page after the last line and insert
AutoText (AutoText contains the whole page with bookmarks) ?

Robert
Author
29 May 2005 9:15 AM
Steve Barnett
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


Show quoteHide quote
"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
>