View Full Version : Need a answer
qumsiehm
Feb 14, 2009, 05:55 AM
Hi All..
listen I'm programing a program and I have a problem!
that problem is that I need to open a Microsoft document by using visual basic
I just need to open it like that
if combo1.text = 1 then ""open the document1.doc from c:\data\document1.doc"
if combo1.text = 2 then ""open the socument2.doc from c:\data\document2.doc"
e.t.c...
then I will make a changes and save it in a document form!
if u know the answer! Please help!
Very thankful!
rwinterton
Feb 14, 2009, 07:02 AM
Hi All..!
I'm writing a program and i have a problem!
That problem is that I need to open a microsoft document by using visual basic
I just need to open it like that
if combo1.text = 1 then ""open the document1.doc from c:\data\document1.doc"
if combo1.text = 2 then ""open the socument2.doc from c:\data\document2.doc"
e.t.c....
then i will make a changes and save it in a document form!
I'm not sure I understand your question.
There are many ways to open documents. If it is a Microsoft Word document, I'd suggest using COM (ActiveX) to cause Word to open the document.
If you are editing a text file you can use the Visual Basic "OPEN" command or Visual Basic.NET's StreamReader and StreamWriter classes to open and edit a file. You'll also have to create some object (a memo object, for example) to allow the user to edit the file.
You should also use a Select Case statement
Select case Combo1.text
Case 1:...
Case 2:...
Case 3:...
End Select
Now, I suspect I haven't answered your question, so please elaborate and I'll do what I can.
qumsiehm
Feb 14, 2009, 07:43 AM
U didn't understand my question
I want to make a program that will work with
Microsoft word..
I will make a table in Microsoft word then I will
Put a code that will open this file as a Microsoft word file using Microsoft office
I think there is a small and easy code that will do this!
Thanks!
rwinterton
Feb 14, 2009, 10:09 AM
Actually, I thought it might be that. Note what I said:
"There are many ways to open documents. If it is a Microsoft Word document, I'd suggest using COM (ActiveX) to cause Word to open the document."
To do that, add a reference to the "Microsoft Word ## Object Library". "##" is the version of Word that is on the computer. That will make the Word functions available to you.
You can also use CreateObject(). This is VB6 code:
Dim Word
Set Word = CreateObject ("word.application")
This is code from Visual Basic.NET 2008. Other .NET versions are essentially identical and VB6 is similar. . NET doesn't use the "SET" keyword.
Dim word As New Microsoft.Office.Interop.Word.Application
Dim doc As Document
Dim filename as string
filename = "Test.doc" ' you'll want to pass this in a variable.
word.Visible = True ' This makes Word visible so the user can edit the document. You may not want this.
doc = word.Documents.Open(filename)
' Manipulate the document as desired,
doc.Save() ' this saves the document to the file.
doc.Close() ' this closes the document. It does not close "Word".
End Sub
trinopoty
Mar 11, 2009, 06:35 AM
The problem is you have to use the following code:
if combo1.text = 1 then
"open the document1.doc from c:\data\document1.doc"
elseif combo1.text = 2 then "open the socument2.doc from c:\data\document2.doc"
elseif
...
endif