473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Writing to word from VB.NET

Hi
I am attempting to write some data from my program to a word document using a template. This is simple enough as there are plenty of tutorials around.

What I would like to know is how can I duplicate a page in the word document depending on data in the program.

To be more specific the user enters product data into the program. Most times it will be only one product however sometimes it will be 2 or 3 products. When it is more than one product I will need to duplicate a page in the word document to enter the second or third product information.
Jun 22 '11 #1

✓ answered by Simon Davis

Found some code that does what I want.
Expand|Select|Wrap|Line Numbers
  1. oDoc = oWord.Documents.Add("H:\QuoteTemplate.dot")
  2.  
  3.         range = oDoc.Bookmarks.Item("ProductPage").Range
  4.  
  5.         range.Select()
  6.         range.Application.ActiveWindow.Selection.Copy()
  7.         range.Select()
  8.         range.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
  9.         range.Select()
  10.         range.Paste()
  11.         range.Select()
  12.         oDoc.Bookmarks.Add("ProductPage2", CType(range, Word.Range))
  13.         range = oDoc.Bookmarks.Item("ProductPage").Range
  14.         range.Select()
  15.         With range.Find
  16.             .Text = "<<Product>>"
  17.             .Replacement.Text = "blah blah blah"
  18.         End With
  19.         range.Find.Execute(Replace:=Word.WdReplace.wdReplaceOne)

1 4868
Found some code that does what I want.
Expand|Select|Wrap|Line Numbers
  1. oDoc = oWord.Documents.Add("H:\QuoteTemplate.dot")
  2.  
  3.         range = oDoc.Bookmarks.Item("ProductPage").Range
  4.  
  5.         range.Select()
  6.         range.Application.ActiveWindow.Selection.Copy()
  7.         range.Select()
  8.         range.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
  9.         range.Select()
  10.         range.Paste()
  11.         range.Select()
  12.         oDoc.Bookmarks.Add("ProductPage2", CType(range, Word.Range))
  13.         range = oDoc.Bookmarks.Item("ProductPage").Range
  14.         range.Select()
  15.         With range.Find
  16.             .Text = "<<Product>>"
  17.             .Replacement.Text = "blah blah blah"
  18.         End With
  19.         range.Find.Execute(Replace:=Word.WdReplace.wdReplaceOne)
Jun 22 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Daniel Cloutier | last post by:
Hi, is it possible to edit or write Word-files out of a Python-Program? thx in advance daniel
5
by: Joan | last post by:
I am creating a word document from an asp page. I have no problems actaully creating the document and creating some tables that have data in them. I am using Response.ContentType =...
5
by: Raj | last post by:
Hi , I am working on vb.net and word application automation application. my question is :. 1. I want to save one file into another file , example. a) my existing file name is "Raj.DOc"...
1
by: Simon | last post by:
How can I create a Macro in VB generated Word document. It would be nice to add a Button to to the Word Doc too...
4
by: JensB | last post by:
I have VB.Net VS2005 App which creates MS Word documents. Clients are using Word 2000 and Word2003. Project refers to MS Word 9.0 Object library, declaring Word as an object. On the Word 2000...
9
by: jerry.upstatenyguy | last post by:
I am really stuck on this. I am trying to write a string array containing a "word" and a "definition" to a class called Entry. Ultimately this will end up in another class called dictionary. No,...
1
by: R | last post by:
Hi, How can I write a word document to a database - I get the document as an object (it is embedded within excel file) and I would like to add it to the db. Thanks
7
by: giladp1 | last post by:
I found Albert Kallal's great "Super easy Word Merge" code in his site at: http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html Thanks Albert so much for sharing this. I am looking...
2
by: RobcPettit | last post by:
Hi, Im using streamwriter to write to notepad or word. No problems with this. Is it possible to write to either notpad or word, while the document is open, and the data to update as its written....
0
by: talk2pk | last post by:
When i am writing the images to the word file(using Clipboard.SetImage) and open another word doc, the process of writing those images migrates to the new opened document. Can anybody suggest why...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.