Ask Experts Questions for FREE Help!
 

Free Answers in 3 Easy Steps

Register Now
3 Steps
 


Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.
  View Answers    Answer this question    Ask a question  
 

qumsiehm
Feb 14, 2009, 04: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 you know the answer! Please help!

Very thankful!

rwinterton
Feb 14, 2009, 06: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, 06:43 AM
You 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, 09: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