|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
VB 6 and MS-Word questionI 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 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 > > 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 >> >> > > 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 >>> >>> >> >> > > What about using AutoText. Create a new page after the last line and insert
AutoText (AutoText contains the whole page with bookmarks) ? Robert 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 >
Accelerating Extraction of Bits From Text
Generate email from user Form Quotation mark as string VB6 vs VB.net compatibility How do you make child sub-commands visible in DataReport controls? Releasing lock on MDB file after DataReport1 closes Can VB6 & VB.net co-exist How do I put the focus back in a text box One procedure for a textbox array? |
|||||||||||||||||||||||