473,811 Members | 2,879 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 4890
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
4327
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
13294
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 = "application/vnd.ms-word" to create the actual document. My problem is that I want to place a picture (which resides on the server) into the word document as well. However all I seem to get is the place for the image but a picture of an "x" meaning that the...
5
1310
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" and containing some page.
1
1449
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
3697
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 machines this works fast and nice, but on the Word 2003 machines it takes 5-10 times longer. Is there a way to make Word 2003 clients to work faster? Recently a warning message, showed up in the error list: "There are updated custom wrappers...
9
2101
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, this is not a homework assignment. In fact it was a question on my class midterm that everyone bombed. Unfortunately we never covered this in class prior to the midterm. Anyway, please help if you would be so kind. Here is what I have. I...
1
1221
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
7245
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 for any comments about the use of the docmd.transfertext method instead of the code Albert used for creating the text file. Also, perhaps some ideas for coding the Subject Line of each email so
2
2794
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. At the momment notepad has to be closed, saved and reopened to see the data. Word doesnt allow me to write to it whilst its open. Regards Robert
0
1259
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 this is happening? The requirement is to write the images in the file which i have specified.The opening of another word doc should not effect the process. Here is the code: document.Application.Selection.TypeText("\n"); ...
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6882
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.