473,699 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copy Word Doc Line by Line

6 New Member
I need to open a word doc and copy each line into a variable lets say
dim Sline as string
May 8 '07 #1
11 4055
SammyB
807 Recognized Expert Contributor
I need to open a word doc and copy each line into a variable lets say
dim Sline as string
Ae you sure you mean lines and not sentences? Here's for lines:
Expand|Select|Wrap|Line Numbers
  1.     Selection.HomeKey Unit:=wdStory     ' Move to the begining of the document
  2.     Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend     ' Select a line
  3.     Dim line1 As String
  4.     line1 = Selection.Text ' Save the line
  5.     Selection.MoveRight Unit:=wdCharacter, Count:=1     ' Move to the next line
  6.     Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
  7.     Dim line2 As String
  8.     line2 = Selection.Text
May 8 '07 #2
Killer42
8,435 Recognized Expert Expert
I'd guess that anj755 is referring to "paragraphs ".
May 9 '07 #3
anj755
6 New Member
I was actually wondering if we could do a search for CRLF and then recognize it as a line. I am database person, not much of a .net programmer, so any help will really make my work easier.
May 9 '07 #4
SammyB
807 Recognized Expert Contributor
I was actually wondering if we could do a search for CRLF and then recognize it as a line. I am database person, not much of a .net programmer, so any help will really make my work easier.
Ah, that is simple: Word has already done all of the work. Word already separates your document with the CRLF into what it calls paragraphs and keeps them in a collection, so if you want the text from paragraph i, it is:
ActiveDocument. Paragraphs(i).R ange.Text
May 9 '07 #5
anj755
6 New Member
How do I get wdStory or wdLine
Seems like I need Word.dll
but all I can find in my machine is microsoft.offic e.interop.word. dll
I found word.dll in the web but it is not strong named.
Is there a way arround it?
May 9 '07 #6
anj755
6 New Member
Okay I found a way to get arround it. But now I can't seem to figure how to do
while not EOF for the word doc?
May 9 '07 #7
SammyB
807 Recognized Expert Contributor
How do I get wdStory or wdLine
Seems like I need Word.dll
but all I can find in my machine is microsoft.offic e.interop.word. dll
I found word.dll in the web but it is not strong named.
Is there a way arround it?
You need to add a reference to microsoft.offic e.interop.word. dll and then use http://www.thescripts.com/forum/thread348663.html as an example for the open, but look at http://support.microsoft.com/?kbid=315981 to see how to quit Word.

While in Word, use objDoc.Paragrap hs(i).Range.Tex t to get paragraph i.

But, is this a Windows App or a Web App? I think there are more problems with a Web App.
May 9 '07 #8
Killer42
8,435 Recognized Expert Expert
Okay I found a way to get arround it. But now I can't seem to figure how to do while not EOF for the word doc?
If the paragraphs are in a collection, then I expect you can use a For Each loop to go through them, plus there should be a .Count property to tell you how many there are (if you need to know).
May 9 '07 #9
SammyB
807 Recognized Expert Contributor
Okay I found a way to get arround it. But now I can't seem to figure how to do
while not EOF for the word doc?
Killer is spot on.
Expand|Select|Wrap|Line Numbers
  1. Sub Macro4()
  2.     Dim p As Paragraph
  3.     For Each p In ActiveDocument.Paragraphs
  4.         MsgBox p.Range.Text
  5.     Next p
  6. End Sub
  7. Sub Macro5()
  8.     Dim i As Integer
  9.     For i = 1 To ActiveDocument.Paragraphs.Count
  10.         MsgBox ActiveDocument.Paragraphs(i).Range.Text
  11.     Next i
  12. End Sub
May 10 '07 #10

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

Similar topics

7
2087
by: MLH | last post by:
Building Applications with Microsoft Access 97 is a publication I think I need. Is it available in book form? Is MicroSoft the sole vendor? Anybody got a copy they wanna sell???
1
6746
by: Jeffrey Bradshaw | last post by:
Is there any way to make a copy of a word.range object? I have a range in a document and I need to monkey around with it but I don't want to change the original in the document. I've tried Duplicate() and assigning it to a new variable. But if I change the stuff in the new variable, it changes the original also. So what I need is a new copy of the variable - not pointing to the same thing. TIA - Jeffrey
7
11624
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an OpenFileDialog: Dim result As DialogResult = Pic_Sel.ShowDialog() If (result = DialogResult.OK) Then
6
8475
by: George | last post by:
Hi All, I'm trying to learn c++/stl. I'd like a fancy way to read lines of an ascii file into vector of stringbufs. I made a first attempt, but the compiler complains about private constructors in streambuf. I'd like to use algorithms instead of a loop, but I don't know if that is possible. Any ideas? Thanks in advance.
7
10958
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed this screen below. Please help, thanks in advance... Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify...
2
3863
by: alexsg | last post by:
I'm setting up a resolutions database where each resolution will be copied from Word documents and pasted into a memo field. The resolution will be in the form: Resolution title <cr> Project no <cr> Date <cr> Meeting Type <cr> Resolution (up to several paragraphs separated by carriage returns etc).
0
2003
by: garethrichardadams | last post by:
Hi, I've got this bit of code off the interweb and everyone and their dog says it should work. But it doesn't... For some reason the line wordDoc.ActiveWindow.Selection.Copy() doesn't copy anything into the clipboard so the line fileContent = data.GetData(System.Windows.Forms.DataFormats.Text).ToString() fails daying data is nothing. Has anyone else had this problem or am I just special??
13
5011
by: blangela | last post by:
I have decided (see earlier post) to paste my Word doc here so that it will be simpler for people to provide feedback (by directly inserting their comments in the post). I will post it in 3 parts to make it more manageable. Below is a draft of a document that I plan to give to my introductory C++ class. Please note that I have purposely left out any mention of safety issues in the ctors which could be resolved thru some combination...
4
12437
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
0
8705
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
8628
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
9054
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...
1
8943
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8899
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6550
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
5884
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
4391
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2016
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.