Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening Word From VB 1

Status
Not open for further replies.

moonoo

Programmer
May 17, 2000
62
US
Hi
How do i open an existing word documnet from VB .
Now i am using the code something like this

Dim word1 As Application
Dim d As Word.Document

Set word1 = GetObject("Word.Application")
Set d = word1.Documents.Add("C:\My.doc")
word1.Application.Visible = True

But its giving problem in the second line.
Do anybody know any other method of opening
an existing help..

Expecting an early reply..
 
I use the following code with no problems.

Public wdApp As New Word.Application
Public wdDoc As Word.Document
Set wdDoc = wdApp.Documents.Open("c:\myDoc.doc")

Assuming it is VB6 you are using.
 
If you are using Access try the FollowHyperlink command - works a treat and so simple

Cheers
Georg
 
Try this it check if wors is already running first

Dim strFileName As String, oWord As Word.Application, WordWasNotRunning As Boolean,oDoc As Word.Document

strFileName = "XXX.doc"

On Error Resume Next
Set oWord = GetObject(, "Word.application")
If Err Then
Set oWord = New Word.Application
WordWasNotRunning = True
End If

Set oDoc = oWord.Documents.Open(strFileName)

oWord.Visible = True
oWord.Activate
 
Thanks a lot lufc,
This code is working(i.e not giving any errors) but the file is not opening although word is@opening . I have
checked evything still it is giving the same problem..
Please help
Regards
Dev
 
Thanks markbeeson
Though I am working with Vb 6.0 Still it is giving
the same problem . Your code
Set wdDoc = wdApp.Documents.Open("c:\myDoc.doc")
is too giving Error No 5174
Please help
Regards
Dev
 
Check you are accessing the Microsoft Word 8.0 Object Library and check the scope of your declarations first. The trouble with this method is if your application terminates abnormally and you haven't set the wdApp object to nothing then next time you try to run it will start another instance and conflcit with one that is already running, easy to sort out on NT you can just kill the process in the Task Manager. Make sure you are running no instances of Word, visible or not when you kick your app off. hope this helps.
 

HI there,

I am going crazy as I try to write some code to automate a Word doc with forms. all I want to do is select an option from a dropdown field at the beginning and, as a consequence, set some default values for other fields in the doc. What I wrote is as simple as this:

Sub aaaaa()

If ActiveDocument.FormFields("Dropdown1").DropDown.Value = 2 Then

Set ActiveDocument.FormFields("Text1").TextInput.Default = "y"

ActiveDocument.FormFields("Dropdown2").DropDown.Default = 1
End If

If ActiveDocument.FormFields("Dropdown1").DropDown.Value = 1 Then

Set ActiveDocument.FormFields("Text1").TextInput.Default = "n"

ActiveDocument.FormFields("Dropdown2").DropDown.Default = 2


End If
End Sub

(...yet it does not work !)

If you can give me a tip I would be immensely gratefull !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top