|
-
Oct 29th, 2009, 11:17 AM
#1
Thread Starter
Frenzied Member
Reading Microsoft Word Documents
Hi all,
I'm trying to read a word document for the purpose of obtaining a word count, I realise Word has built in functionality for presenting a word count but I want to write a little app that will omit certain parts of the document from the word count.
So far I have tried this code to open the document but I am getting an error 'Word.Document cannot be found' and 'Microsoft.Office.Interop cannot be found'. I have added a reference to the Microsoft Office 12.0 Object Library under the COM tab. I have Office 2007 installed and I'm using VB2005.
Code:
Imports Microsoft.Office.Interop
Dim appWord As New Microsoft.Office.Core.Application
Dim docWord As New Word.Document
docWord = appWord.Documents.Open("c:\test.doc")
Any ideas?
-
Oct 29th, 2009, 11:24 AM
#2
Re: Reading Microsoft Word Documents
Try this...
Code:
'~~> Set reference to Microsoft 12.0 Object Library
Private Sub cmdOpen_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmdOpen.Click
Dim strFileName As String, strFilePath As String, strFileTitle As String
Dim word_server As Word.Application
Application.DoEvents()
strFileName = "c:\test.doc"
strFileTitle = strFileName.Substring(strFileName.LastIndexOf("\") + 1)
strFilePath = strFileName.Substring(0, strFileName.LastIndexOf("\"))
word_server = New Word.Application()
word_server.ChangeFileOpenDirectory (strFilePath)
word_server.Documents.Open(FileName:=strFileTitle, _
ConfirmConversions:=False, ReadOnly:=False, _
AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", _
Format:=Word.WdOpenFormat.wdOpenFormatAuto)
word_server.Visible = True
'~~> What ever you want to do here...
End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 29th, 2009, 01:23 PM
#3
Thread Starter
Frenzied Member
Re: Reading Microsoft Word Documents
Hi koolsid, thanks for the quick reply...
Unfortunately I am still getting the same error (Word.Application is not defined) on the line:
Code:
word_server = New Word.Application()
I have selected the reference to MS Office 12 Object Library, how can I verify this is attached to my project?
-
Oct 29th, 2009, 01:30 PM
#4
Re: Reading Microsoft Word Documents
I have selected the reference to MS Office 12 Object Library, how can I verify this is attached to my project?
The moment you type
word_server = New Word.
Intellisense should give you Application()
or when you type
Dim word_server As
Intellisense should give you Word.Application
Edit: How are you selecting the reference?
Last edited by Siddharth Rout; Oct 29th, 2009 at 01:36 PM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 29th, 2009, 02:36 PM
#5
Fanatic Member
Re: Reading Microsoft Word Documents
I have selected the reference to MS Office 12 Object Library, how can I verify this is attached to my project?
Are you sure you have the correct PIA's (Primary Interop Assemblies)installed on your system?
PIA Download: http://www.microsoft.com/downloads/d...displaylang=en
^^For office '07
Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".
VS 2008 .NetFW 2.0
-
Oct 30th, 2009, 05:41 AM
#6
Thread Starter
Frenzied Member
Re: Reading Microsoft Word Documents
 Originally Posted by BackWoodsCoder
I installed this but nothing has changed - even after a reboot. I'm not sure if they installed correctly though because there was no 'finished' or 'success' message, after running the setup the progress bar advances then the window disappears. Could be a problem with Vista?
 Originally Posted by koolsid
How are you selecting the reference?
All I do is go to Project>Add Reference>COM>Select Microsoft Office 12.0 Object Library>OK
-
Oct 30th, 2009, 06:15 AM
#7
Re: Reading Microsoft Word Documents
What about the intellisense question in post 4?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 30th, 2009, 07:28 AM
#8
Thread Starter
Frenzied Member
Re: Reading Microsoft Word Documents
Hi mate, There's no item in the intellisense list called 'Word'. VS underlines Word.Application with the error 'Word.Application is not defined'.
-
Oct 30th, 2009, 07:49 AM
#9
Re: Reading Microsoft Word Documents
Just a stupid doubt...
How many office versions are installed in your pc? What I mean is do you have 2003 and 2007 together?
If no then can you upload your project?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 30th, 2009, 08:36 AM
#10
Thread Starter
Frenzied Member
Re: Reading Microsoft Word Documents
Good point, I have only Office 2007, but I do have MS Office Powerpoint Viewer 2003. Could that be causing the problem?
Last edited by the182guy; Oct 30th, 2009 at 08:52 AM.
Chris
-
Oct 30th, 2009, 08:55 AM
#11
Re: Reading Microsoft Word Documents
All I do is go to Project>Add Reference>COM>Select Microsoft Office 12.0 Object Library>OK
 Originally Posted by the182guy
Good point, I have only Office 2007, but I do have MS Office Powerpoint Viewer 2003. Could that be causing the problem?
Ok post a snapshot of the screen when you are adding references....
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|