473,500 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing to word from VB.NET

2 New Member
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
1 4873
Simon Davis
2 New Member
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
4309
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
13270
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
1303
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
1429
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
3681
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
2081
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
1213
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
7224
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
2777
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
1243
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
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.