473,806 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Call WORD via VB.Net

Hi,
I want to try call/run Ms. Word via my VB.Net
First I added reference : Microsoft Word 11.0 Object Library. Then I got 2 references in my reference list : Word and Microsoft.Offic e.Core

When I typed :
Dim objWord as Word.Applicatio n
Dim objDocument as Word.Document

I got an error (underline at Word.Applicatio n and Word.Document).
What is actually happen ?
Can anybody tell how to do what I want ?

Thanks in advance.
Joachim
Nov 20 '05 #1
8 11303
Joachim wrote:
I want to try call/run Ms. Word via my VB.Net
First I added reference : Microsoft Word 11.0 Object Library. Then I got 2 references in my reference list : Word and Microsoft.Offic e.Core

When I typed :
Dim objWord as Word.Applicatio n
Dim objDocument as Word.Document

I got an error (underline at Word.Applicatio n and Word.Document).
What is actually happen ?
Can anybody tell how to do what I want ?


Hi Joachim,

seems you have Office XP PIAs installed
http://www.microsoft.com/downloads/d...4-01FEBA508E52

It should be

Microsoft.Offic e.Interop.Word. ApplicationClas s
Microsoft.Offic e.Interop.Word. DocumentClass

Understanding the Word Object Model from a .NET Developer's Perspective:
http://msdn.microsoft.com/vstudio/of...wordobject.asp

Cheers

Arne Janning

Nov 20 '05 #2
Joachim wrote:

hi Joachim,

insert a pagebreak after each record:

objWord.Selecti on.InsertBreak (Type:=wdPageBr eak)
or
objWord.Range.I nsertBreak (Type:=wdPageBr eak)

Cheers
Arne Janning
Thanks Arne,

It works now.
I have one more problem/question. I hope you can help me out.

I have a templete (WORD templete) : MyTemplete.dot
This is a 1 page templete with several bookmarks.
I want to "print out" all my data/record with MyTemplete file via VB.Net.
1 page for 1 record, but all of the pages should be in 1 document.
Ex. : 50 records mean 50 pages WORD document.
The problem is : What should I do to make 1 record 1 page ?

Thanks in advance,
Regards,
Joachim.
Below is my code :
====
Private sub PrintwithWord()
Dim objWord As Word.Applicatio n
Dim objDocument As Word.Document
objWord = CType(CreateObj ect("Word.Appli cation"), Word.Applicatio n)
objDocument = CType(objWord.D ocuments.Open(A ppPath & "MyExamen.dot") , Word.Document)

For i = 1 To TotalRecords
ReadRecord()
objDocument = CType(objWord.D ocuments.Open(A ppPath & "MyTempelte.dot "), Word.Document)
objWord.Visible = True
If objDocument Is Nothing Then
MsgBox("The Templete file not fond !", MsgBoxStyle.Cri tical, "Error")
Exit Sub
End If
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks1").Range.Te xt = MyField1
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks2").Range.Te xt = MyField2
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks3").Range.Te xt = MyField3
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks4").Range.Te xt = MyField4
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks5").Range.Te xt = MyField5
objDocument.Pri ntPreview()
objDocument.Sav eAs(UserPath & "\" & "-Text" & ".doc")
objDocument.Clo se()
Next
objWord.Visible = False
CLoseWord()
End Sub
=====


"Arne Janning" wrote:
Hi Joachim,

seems you have Office XP PIAs installed
http://www.microsoft.com/downloads/d...4-01FEBA508E52

It should be

Microsoft.Off ice.Interop.Wor d.ApplicationCl ass
Microsoft.Off ice.Interop.Wor d.DocumentClass

Understandi ng the Word Object Model from a .NET Developer's Perspective:
http://msdn.microsoft.com/vstudio/of...wordobject.asp

Cheers

Arne Janning


Nov 20 '05 #3
Thanks Arne,

There is no "objWord.Range. InsertBreak (Type:=wdPageBr eak)"
I did add : "objWord.Select ion.InsertBreak (Type:=wdPageBr eak)"
But I got error (underline) at (Type:=wdPageBr eak)

What I have done is :
I inserted "objWord.Select ion.InsertBreak (Type:=wdPageBr eak)" after bookmark5.
I relocated :
objDocument.Pri ntPreview()
objDocument.Sav eAs(UserPath & "\" & "-Text" & ".doc")
objDocument.Clo se()
to after NEXT statement.

Why I got an error ?

Regards,
Joachim

"Arne Janning" wrote:
hi Joachim,

insert a pagebreak after each record:

objWord.Selecti on.InsertBreak (Type:=wdPageBr eak)
or
objWord.Range.I nsertBreak (Type:=wdPageBr eak)

Cheers
Arne Janning


Nov 20 '05 #4
Thanks Arne,

It works now.
I have one more problem/question. I hope you can help me out.

I have a templete (WORD templete) : MyTemplete.dot
This is a 1 page templete with several bookmarks.
I want to "print out" all my data/record with MyTemplete file via VB.Net.
1 page for 1 record, but all of the pages should be in 1 document.
Ex. : 50 records mean 50 pages WORD document.
The problem is : What should I do to make 1 record 1 page ?

Thanks in advance,
Regards,
Joachim.
Below is my code :
====
Private sub PrintwithWord()
Dim objWord As Word.Applicatio n
Dim objDocument As Word.Document
objWord = CType(CreateObj ect("Word.Appli cation"), Word.Applicatio n)
objDocument = CType(objWord.D ocuments.Open(A ppPath & "MyExamen.dot") , Word.Document)

For i = 1 To TotalRecords
ReadRecord()
objDocument = CType(objWord.D ocuments.Open(A ppPath & "MyTempelte.dot "), Word.Document)
objWord.Visible = True
If objDocument Is Nothing Then
MsgBox("The Templete file not fond !", MsgBoxStyle.Cri tical, "Error")
Exit Sub
End If
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks1").Range.Te xt = MyField1
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks2").Range.Te xt = MyField2
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks3").Range.Te xt = MyField3
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks4").Range.Te xt = MyField4
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks5").Range.Te xt = MyField5
objDocument.Pri ntPreview()
objDocument.Sav eAs(UserPath & "\" & "-Text" & ".doc")
objDocument.Clo se()
Next
objWord.Visible = False
CLoseWord()
End Sub
=====


"Arne Janning" wrote:
Hi Joachim,

seems you have Office XP PIAs installed
http://www.microsoft.com/downloads/d...4-01FEBA508E52

It should be

Microsoft.Offic e.Interop.Word. ApplicationClas s
Microsoft.Offic e.Interop.Word. DocumentClass

Understanding the Word Object Model from a .NET Developer's Perspective:
http://msdn.microsoft.com/vstudio/of...wordobject.asp

Cheers

Arne Janning


Nov 20 '05 #5
Joachim wrote:
It should like this :
objWord.Selecti on.InsertBreak( Word.WdBreakTyp e.wdPageBreak)

But the result is not what I like.
I have 5 records (just for trying). The first 4 pages are empty.
The last page gives me the result, but like this :
(The first bookmark is Name)
Name : Name1NAme2Name3 Name4Name5
Address : Adr1Adr2Adr3Adr 4Adr5
They stick together in one line.

What I should do now ?
Please help me....


What is the code you're actually using?

Cheers

AJ
Nov 20 '05 #6
> What is the code you're actually using?

Cheers

AJ


Hi, Arne.

Here is my code :
======
Private sub PrintwithWord()
Dim objWord As Word.Applicatio n
Dim objDocument As Word.Document
objWord = CType(CreateObj ect("Word.Appli cation"), Word.Applicatio n)
objDocument = CType(objWord.D ocuments.Open(A ppPath & "MyExamen.dot") , Word.Document)

For i = 1 To TotalRecords
ReadRecord()
objDocument = CType(objWord.D ocuments.Open(A ppPath & "MyTempelte.dot "), Word.Document)
objWord.Visible = True
If objDocument Is Nothing Then
MsgBox("The Templete file not fond !", MsgBoxStyle.Cri tical, "Error")
Exit Sub
End If
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks1").Range.Te xt = MyField1
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks2").Range.Te xt = MyField2
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks3").Range.Te xt = MyField3
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks4").Range.Te xt = MyField4
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks5").Range.Te xt = MyField5

' I have tried all of two, but got the same result.
'objWord.Select ion.InsertBreak (Word.WdBreakTy pe.wdPageBreak)
objDocument.Act iveWindow.Selec tion.InsertBrea k()
Next
objWord.Visible = False
objDocument.Pri ntPreview()
objDocument.Sav eAs(UserPath & "\" & "-Text" & ".doc")
objDocument.Clo se()
CLoseWord()
End Sub
Nov 20 '05 #7
Joachim wrote:
Hi, Arne.

Here is my code :
======
Private sub PrintwithWord()
Dim objWord As Word.Applicatio n
Dim objDocument As Word.Document
objWord = CType(CreateObj ect("Word.Appli cation"), Word.Applicatio n)
objDocument = CType(objWord.D ocuments.Open(A ppPath & "MyExamen.dot") , Word.Document)

For i = 1 To TotalRecords
ReadRecord()
objDocument = CType(objWord.D ocuments.Open(A ppPath & "MyTempelte.dot "), Word.Document)
objWord.Visible = True
If objDocument Is Nothing Then
MsgBox("The Templete file not fond !", MsgBoxStyle.Cri tical, "Error")
Exit Sub
End If
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks1").Range.Te xt = MyField1
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks2").Range.Te xt = MyField2
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks3").Range.Te xt = MyField3
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks4").Range.Te xt = MyField4
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks5").Range.Te xt = MyField5

' I have tried all of two, but got the same result.
'objWord.Select ion.InsertBreak (Word.WdBreakTy pe.wdPageBreak)
objDocument.Act iveWindow.Selec tion.InsertBrea k()
Next
objWord.Visible = False
objDocument.Pri ntPreview()
objDocument.Sav eAs(UserPath & "\" & "-Text" & ".doc")
objDocument.Clo se()
CLoseWord()
End Sub

Hi Joachim,

2 thoughts:

1. objWord is never saved? You only save objDocument?
2. objDocument.Act iveWindow.Selec tion.InsertBrea k(). Where is the
Selection during runtime? At the end of the page? At the top? Don't you
have to set the selection to the end of the page before calling
InsertBreak()? You will only get empty pages otherwise.

Cheers

Arne Janning
Nov 20 '05 #8
Great to see you.
Finally I get your reply, I have waited for this.
As a beginner, I don't know how to code it, I just try myself.
What I want is 1 record 1 page in WORD and all record in one .DOC file.
So Arne, how should I code it ?
Will you change my code to meet what I want, please ?
Please help me out Arne !

"Arne Janning" wrote:
Joachim wrote:
Hi, Arne.

Here is my code :
======
Private sub PrintwithWord()
Dim objWord As Word.Applicatio n
Dim objDocument As Word.Document
objWord = CType(CreateObj ect("Word.Appli cation"), Word.Applicatio n)
objDocument = CType(objWord.D ocuments.Open(A ppPath & "MyExamen.dot") , Word.Document)

For i = 1 To TotalRecords
ReadRecord()
objDocument = CType(objWord.D ocuments.Open(A ppPath & "MyTempelte.dot "), Word.Document)
objWord.Visible = True
If objDocument Is Nothing Then
MsgBox("The Templete file not fond !", MsgBoxStyle.Cri tical, "Error")
Exit Sub
End If
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks1").Range.Te xt = MyField1
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks2").Range.Te xt = MyField2
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks3").Range.Te xt = MyField3
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks4").Range.Te xt = MyField4
objWord.ActiveD ocument.Bookmar ks.Item("Bookma rks5").Range.Te xt = MyField5

' I have tried all of two, but got the same result.
'objWord.Select ion.InsertBreak (Word.WdBreakTy pe.wdPageBreak)
objDocument.Act iveWindow.Selec tion.InsertBrea k()
Next
objWord.Visible = False
objDocument.Pri ntPreview()
objDocument.Sav eAs(UserPath & "\" & "-Text" & ".doc")
objDocument.Clo se()
CLoseWord()
End Sub

Hi Joachim,

2 thoughts:

1. objWord is never saved? You only save objDocument?
2. objDocument.Act iveWindow.Selec tion.InsertBrea k(). Where is the
Selection during runtime? At the end of the page? At the top? Don't you
have to set the selection to the end of the page before calling
InsertBreak()? You will only get empty pages otherwise.

Cheers

Arne Janning


Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
2275
by: TTroy | last post by:
Hi, I'm just wondering why people/books/experts say "the function returns a pointer to.." or "we have to send scanf a pointer to.." instead of "the function returns the address of.." or "we have to send scanf the address of.." Isn't the lvalue called a POINTER TO and the (r)value called the ADDRESS OF?
10
2462
by: Brian Kwan | last post by:
Requirement: Call a Word Macro from ASP.NET with parameters Do anyone have idea about this? Please notice the import statement and sample code, as I am a beginner using ASP.NET, thanks for your kindly reply!
1
1438
by: NewAlias | last post by:
I still can't make APIs with structures to work at first time in VB .NET This is a required function to be called prior to use ScriptStringOut to display unicode complex scripts The famigerate message shows for the signaled line: :: An unhandled exception of type 'System.NullReferenceException' occurred in MyTest.exe :: Additional information: Object reference not set to an instance of an object.
1
1703
by: news.onet.pl | last post by:
Hello! I have a small question concerning to the procedure call. I have the following procedure: private sub procedure_name (ByVal name1 as string) .... end sub When I call it I just write:
2
4661
by: Gilles Vollant \(MVP\) | last post by:
Hello I've (in WinImage SDK http://www.winimage.com/wima_sdk.htm ) a function that I need to use from a VB.Net apps First, on the unmanaged Win32 DLL, I've a function which get the number of item (function GetNbEntryCurDir) after, I allocate an array and I call GetDirInfo to fill the array
10
16678
by: ravi | last post by:
Hi, i am a c++ programmer, now i want to learn programming in c also. so can anybody explain me the difference b/w call by reference and call by pointer (with example if possible).
2
2056
by: dhirajgaherwar | last post by:
Hi everybody, Can anyone tell how to call a standard "Find and Replace dialog box" while my application (embeded word aplication) is at run time. Is there any embeded somewhere ?? or do i have to design one !! i am having a win application that i have created myself on VB. there is no word menu bar. i would like the user to call a standard Find dialog box (Ctrl+F) to jump to a specific line in the treeview for ease in searching and...
1
2207
by: Hvid Hat | last post by:
Hi I want to search and replace multiple words in a text. I've got a template that does the search and replace of a word in a text. Now, I want to call this template for each word in a list of words. If changes are made (words are replaced) in the text, how can I call the search and replace template with this updated text the next time? Current I'm calling it with the original text each time. <?xml version="1.0"?>
0
1147
by: tomb | last post by:
Can anybody help me by checking if I have correct call signatures? In my C# Windows Form project (VS2008) I am using dll which has been written for Visual C++ 6.0: This function code is used to start receive active message of ioLogik 2000 Ethernet Module: C/C++ int Message2K_Start(&nbsp; int iProtocol, WORD wPort, pfnCALLBACK& iProcAddress);
0
9598
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
10371
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
10373
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
9192
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
7650
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
6877
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
5546
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...
1
4330
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 we have to send another system
2
3852
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.