PC Review


Reply
Thread Tools Rate Thread

Automation error. The object invoked has disconnected

 
 
=?Utf-8?B?R3Jhbm55TQ==?=
Guest
Posts: n/a
 
      9th Apr 2007
I've been doing a lot of research on the above error, but haven't found
anything to help with my problem. I have a macro that worked great between
Excel and Word 97, but since we switched to 2003, I keep getting the above
error. The macro is written in excel, but opens a file in Word, and searches
for specific information to pull into an excel spreadsheet. When the macro
executes the "Find" command, it will give the above error and close out
excel. Here is the section of my code causing the problem. If I rem out the
2 "find" lines, (which of course defeats the purpose of the macro!)
everything else runs without problem.

Public myWord As Word.Application

Set myWord = GetObject(, "Word.application")
myWord.Visible = True

myWord.Documents.Open FileName:=ABFileName$, ConfirmConversions:=False,
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="",
WritePasswordTemplate:="", Format:=wdOpenFormatAuto

myWord.ActiveDocument.SaveAs FileName:="i:\rec.txt", FileFormat:=wdFormatText

myWord.Selection.Find.Execute FindText:=O7C$
myWord.Selection.MoveDown Unit:=wdLine, Count:=3
myWord.Selection.HomeKey Unit:=wdLine
myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
myWord.Selection.Delete

myWord.Selection.Find.Execute FindText:="PlanRefNu"
myWord.Selection.HomeKey Unit:=wdLine
myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
myWord.Selection.Delete

myWord.Selection.HomeKey Unit:=wdLine
myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
myWord.Selection.Delete

myWord.ActiveDocument.Save
myWord.ActiveDocument.Close
Set myWord = Nothing

Thanks!

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      9th Apr 2007
try this
Sub mywordtest()


Dim myWord As Word.Application

Set myWord = GetObject(, "Word.application")
myWord.Visible = True

myWord.Documents.Open Filename:=ABFileName$, ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto

myWord.ActiveDocument.SaveAs Filename:="i:\rec.txt", FileFormat:=wdFormatText

myWord.Selection.Find.Execute FindText:=O7C$
myWord.Selection.MoveDown Unit:=wdLine, Count:=3
myWord.Selection.HomeKey Unit:=wdLine
myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
myWord.Selection.Delete

myWord.Selection.Find.Execute FindText:="PlanRefNu"
myWord.Selection.HomeKey Unit:=wdLine
myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
myWord.Selection.Delete

myWord.Selection.HomeKey Unit:=wdLine
myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
myWord.Selection.Delete

myWord.ActiveDocument.Save
myWord.ActiveDocument.Close
Set myWord = Nothing
End Sub

"GrannyM" wrote:

> I've been doing a lot of research on the above error, but haven't found
> anything to help with my problem. I have a macro that worked great between
> Excel and Word 97, but since we switched to 2003, I keep getting the above
> error. The macro is written in excel, but opens a file in Word, and searches
> for specific information to pull into an excel spreadsheet. When the macro
> executes the "Find" command, it will give the above error and close out
> excel. Here is the section of my code causing the problem. If I rem out the
> 2 "find" lines, (which of course defeats the purpose of the macro!)
> everything else runs without problem.
>
> Public myWord As Word.Application
>
> Set myWord = GetObject(, "Word.application")
> myWord.Visible = True
>
> myWord.Documents.Open FileName:=ABFileName$, ConfirmConversions:=False,
> ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="",
> PasswordTemplate:="", Revert:=False, WritePasswordDocument:="",
> WritePasswordTemplate:="", Format:=wdOpenFormatAuto
>
> myWord.ActiveDocument.SaveAs FileName:="i:\rec.txt", FileFormat:=wdFormatText
>
> myWord.Selection.Find.Execute FindText:=O7C$
> myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> myWord.Selection.HomeKey Unit:=wdLine
> myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> myWord.Selection.Delete
>
> myWord.Selection.Find.Execute FindText:="PlanRefNu"
> myWord.Selection.HomeKey Unit:=wdLine
> myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> myWord.Selection.Delete
>
> myWord.Selection.HomeKey Unit:=wdLine
> myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> myWord.Selection.Delete
>
> myWord.ActiveDocument.Save
> myWord.ActiveDocument.Close
> Set myWord = Nothing
>
> Thanks!
>

 
Reply With Quote
 
=?Utf-8?B?R3Jhbm55TQ==?=
Guest
Posts: n/a
 
      9th Apr 2007
Tried your code and now I get a different error. I moved this piece of code
to it's own sub, Dim'd myWord instead of using Public and called the sub from
the rest of the code. Instead of the above error, I now get "Method
'Execute' of object 'Find' failed." So, I did a search for the value of the
variable O7C$ on the Word document to make sure it worked in Word, and it
did. Then I replaced the variable in the code with the value of the
variable, and I still received the failed message above. (At least it's
something different then before!)

"Mike" wrote:

> try this
> Sub mywordtest()
>
>
> Dim myWord As Word.Application
>
> Set myWord = GetObject(, "Word.application")
> myWord.Visible = True
>
> myWord.Documents.Open Filename:=ABFileName$, ConfirmConversions:=False, _
> ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
> PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
> WritePasswordTemplate:="", Format:=wdOpenFormatAuto
>
> myWord.ActiveDocument.SaveAs Filename:="i:\rec.txt", FileFormat:=wdFormatText
>
> myWord.Selection.Find.Execute FindText:=O7C$
> myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> myWord.Selection.HomeKey Unit:=wdLine
> myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> myWord.Selection.Delete
>
> myWord.Selection.Find.Execute FindText:="PlanRefNu"
> myWord.Selection.HomeKey Unit:=wdLine
> myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> myWord.Selection.Delete
>
> myWord.Selection.HomeKey Unit:=wdLine
> myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> myWord.Selection.Delete
>
> myWord.ActiveDocument.Save
> myWord.ActiveDocument.Close
> Set myWord = Nothing
> End Sub
>
> "GrannyM" wrote:
>
> > I've been doing a lot of research on the above error, but haven't found
> > anything to help with my problem. I have a macro that worked great between
> > Excel and Word 97, but since we switched to 2003, I keep getting the above
> > error. The macro is written in excel, but opens a file in Word, and searches
> > for specific information to pull into an excel spreadsheet. When the macro
> > executes the "Find" command, it will give the above error and close out
> > excel. Here is the section of my code causing the problem. If I rem out the
> > 2 "find" lines, (which of course defeats the purpose of the macro!)
> > everything else runs without problem.
> >
> > Public myWord As Word.Application
> >
> > Set myWord = GetObject(, "Word.application")
> > myWord.Visible = True
> >
> > myWord.Documents.Open FileName:=ABFileName$, ConfirmConversions:=False,
> > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="",
> > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="",
> > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> >
> > myWord.ActiveDocument.SaveAs FileName:="i:\rec.txt", FileFormat:=wdFormatText
> >
> > myWord.Selection.Find.Execute FindText:=O7C$
> > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > myWord.Selection.HomeKey Unit:=wdLine
> > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > myWord.Selection.Delete
> >
> > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > myWord.Selection.HomeKey Unit:=wdLine
> > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > myWord.Selection.Delete
> >
> > myWord.Selection.HomeKey Unit:=wdLine
> > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > myWord.Selection.Delete
> >
> > myWord.ActiveDocument.Save
> > myWord.ActiveDocument.Close
> > Set myWord = Nothing
> >
> > Thanks!
> >

 
Reply With Quote
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      9th Apr 2007
one other thing that i don't see is the path to the word document like
C:\MyPath
Set myWord = GetObject("C:\MyPath")
Set myWord = GetObject("C:\MyPath, Word.application")

"GrannyM" wrote:

> Tried your code and now I get a different error. I moved this piece of code
> to it's own sub, Dim'd myWord instead of using Public and called the sub from
> the rest of the code. Instead of the above error, I now get "Method
> 'Execute' of object 'Find' failed." So, I did a search for the value of the
> variable O7C$ on the Word document to make sure it worked in Word, and it
> did. Then I replaced the variable in the code with the value of the
> variable, and I still received the failed message above. (At least it's
> something different then before!)
>
> "Mike" wrote:
>
> > try this
> > Sub mywordtest()
> >
> >
> > Dim myWord As Word.Application
> >
> > Set myWord = GetObject(, "Word.application")
> > myWord.Visible = True
> >
> > myWord.Documents.Open Filename:=ABFileName$, ConfirmConversions:=False, _
> > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
> > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
> > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> >
> > myWord.ActiveDocument.SaveAs Filename:="i:\rec.txt", FileFormat:=wdFormatText
> >
> > myWord.Selection.Find.Execute FindText:=O7C$
> > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > myWord.Selection.HomeKey Unit:=wdLine
> > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > myWord.Selection.Delete
> >
> > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > myWord.Selection.HomeKey Unit:=wdLine
> > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > myWord.Selection.Delete
> >
> > myWord.Selection.HomeKey Unit:=wdLine
> > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > myWord.Selection.Delete
> >
> > myWord.ActiveDocument.Save
> > myWord.ActiveDocument.Close
> > Set myWord = Nothing
> > End Sub
> >
> > "GrannyM" wrote:
> >
> > > I've been doing a lot of research on the above error, but haven't found
> > > anything to help with my problem. I have a macro that worked great between
> > > Excel and Word 97, but since we switched to 2003, I keep getting the above
> > > error. The macro is written in excel, but opens a file in Word, and searches
> > > for specific information to pull into an excel spreadsheet. When the macro
> > > executes the "Find" command, it will give the above error and close out
> > > excel. Here is the section of my code causing the problem. If I rem out the
> > > 2 "find" lines, (which of course defeats the purpose of the macro!)
> > > everything else runs without problem.
> > >
> > > Public myWord As Word.Application
> > >
> > > Set myWord = GetObject(, "Word.application")
> > > myWord.Visible = True
> > >
> > > myWord.Documents.Open FileName:=ABFileName$, ConfirmConversions:=False,
> > > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="",
> > > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="",
> > > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> > >
> > > myWord.ActiveDocument.SaveAs FileName:="i:\rec.txt", FileFormat:=wdFormatText
> > >
> > > myWord.Selection.Find.Execute FindText:=O7C$
> > > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > > myWord.Selection.HomeKey Unit:=wdLine
> > > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > > myWord.Selection.Delete
> > >
> > > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > > myWord.Selection.HomeKey Unit:=wdLine
> > > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > > myWord.Selection.Delete
> > >
> > > myWord.Selection.HomeKey Unit:=wdLine
> > > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > > myWord.Selection.Delete
> > >
> > > myWord.ActiveDocument.Save
> > > myWord.ActiveDocument.Close
> > > Set myWord = Nothing
> > >
> > > Thanks!
> > >

 
Reply With Quote
 
=?Utf-8?B?R3Jhbm55TQ==?=
Guest
Posts: n/a
 
      10th Apr 2007
I'm sorry, I'm confused. I'm setting myWord to Word.Application. Then I'm
opening my document. The path is in the variable ABFileName$. Are you
saying I need to set the path to the document after I open the document? I
tried to insert:
Set myWord = GetObject(ABFileName$, "Word.Application"), but I get "Filename
or Classname not found during Automation Operation. I tried inserting it
both before and after I actually opened the file and get the same error both
places.

I think it's finding the document, because if I rem out the lines with the
Find command, everything else works. I'm wondering if it has something to do
with my references or their order. I have the following references set:

Visual Basic for Applications
Microsoft Excel 11.0 Object Library
OLE Automation
Microsoft Office 11.0 Object Library
Microsoft DAO 2.5 Object Library
Microsoft Forms 2.0 Object Library
Microsoft Visual Basic for Applications Extensibility 5.3
Microsoft Word 11.0 Object Library
Microsoft ActiveX Data Objects 2.8 Library

"Mike" wrote:

> one other thing that i don't see is the path to the word document like
> C:\MyPath
> Set myWord = GetObject("C:\MyPath")
> Set myWord = GetObject("C:\MyPath, Word.application")
>
> "GrannyM" wrote:
>
> > Tried your code and now I get a different error. I moved this piece of code
> > to it's own sub, Dim'd myWord instead of using Public and called the sub from
> > the rest of the code. Instead of the above error, I now get "Method
> > 'Execute' of object 'Find' failed." So, I did a search for the value of the
> > variable O7C$ on the Word document to make sure it worked in Word, and it
> > did. Then I replaced the variable in the code with the value of the
> > variable, and I still received the failed message above. (At least it's
> > something different then before!)
> >
> > "Mike" wrote:
> >
> > > try this
> > > Sub mywordtest()
> > >
> > >
> > > Dim myWord As Word.Application
> > >
> > > Set myWord = GetObject(, "Word.application")
> > > myWord.Visible = True
> > >
> > > myWord.Documents.Open Filename:=ABFileName$, ConfirmConversions:=False, _
> > > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
> > > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
> > > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> > >
> > > myWord.ActiveDocument.SaveAs Filename:="i:\rec.txt", FileFormat:=wdFormatText
> > >
> > > myWord.Selection.Find.Execute FindText:=O7C$
> > > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > > myWord.Selection.HomeKey Unit:=wdLine
> > > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > > myWord.Selection.Delete
> > >
> > > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > > myWord.Selection.HomeKey Unit:=wdLine
> > > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > > myWord.Selection.Delete
> > >
> > > myWord.Selection.HomeKey Unit:=wdLine
> > > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > > myWord.Selection.Delete
> > >
> > > myWord.ActiveDocument.Save
> > > myWord.ActiveDocument.Close
> > > Set myWord = Nothing
> > > End Sub
> > >
> > > "GrannyM" wrote:
> > >
> > > > I've been doing a lot of research on the above error, but haven't found
> > > > anything to help with my problem. I have a macro that worked great between
> > > > Excel and Word 97, but since we switched to 2003, I keep getting the above
> > > > error. The macro is written in excel, but opens a file in Word, and searches
> > > > for specific information to pull into an excel spreadsheet. When the macro
> > > > executes the "Find" command, it will give the above error and close out
> > > > excel. Here is the section of my code causing the problem. If I rem out the
> > > > 2 "find" lines, (which of course defeats the purpose of the macro!)
> > > > everything else runs without problem.
> > > >
> > > > Public myWord As Word.Application
> > > >
> > > > Set myWord = GetObject(, "Word.application")
> > > > myWord.Visible = True
> > > >
> > > > myWord.Documents.Open FileName:=ABFileName$, ConfirmConversions:=False,
> > > > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="",
> > > > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="",
> > > > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> > > >
> > > > myWord.ActiveDocument.SaveAs FileName:="i:\rec.txt", FileFormat:=wdFormatText
> > > >
> > > > myWord.Selection.Find.Execute FindText:=O7C$
> > > > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > > > myWord.Selection.Delete
> > > >
> > > > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > > > myWord.Selection.Delete
> > > >
> > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > > > myWord.Selection.Delete
> > > >
> > > > myWord.ActiveDocument.Save
> > > > myWord.ActiveDocument.Close
> > > > Set myWord = Nothing
> > > >
> > > > Thanks!
> > > >

 
Reply With Quote
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      10th Apr 2007
The path needs to be like GetObject("C:\word.doc", "Word.Application"),
not like GetObject(ABFileName$, "Word.Application"),
If you goto properties of the word document it will give you the path

"GrannyM" wrote:

> I'm sorry, I'm confused. I'm setting myWord to Word.Application. Then I'm
> opening my document. The path is in the variable ABFileName$. Are you
> saying I need to set the path to the document after I open the document? I
> tried to insert:
> Set myWord = GetObject(ABFileName$, "Word.Application"), but I get "Filename
> or Classname not found during Automation Operation. I tried inserting it
> both before and after I actually opened the file and get the same error both
> places.
>
> I think it's finding the document, because if I rem out the lines with the
> Find command, everything else works. I'm wondering if it has something to do
> with my references or their order. I have the following references set:
>
> Visual Basic for Applications
> Microsoft Excel 11.0 Object Library
> OLE Automation
> Microsoft Office 11.0 Object Library
> Microsoft DAO 2.5 Object Library
> Microsoft Forms 2.0 Object Library
> Microsoft Visual Basic for Applications Extensibility 5.3
> Microsoft Word 11.0 Object Library
> Microsoft ActiveX Data Objects 2.8 Library
>
> "Mike" wrote:
>
> > one other thing that i don't see is the path to the word document like
> > C:\MyPath
> > Set myWord = GetObject("C:\MyPath")
> > Set myWord = GetObject("C:\MyPath, Word.application")
> >
> > "GrannyM" wrote:
> >
> > > Tried your code and now I get a different error. I moved this piece of code
> > > to it's own sub, Dim'd myWord instead of using Public and called the sub from
> > > the rest of the code. Instead of the above error, I now get "Method
> > > 'Execute' of object 'Find' failed." So, I did a search for the value of the
> > > variable O7C$ on the Word document to make sure it worked in Word, and it
> > > did. Then I replaced the variable in the code with the value of the
> > > variable, and I still received the failed message above. (At least it's
> > > something different then before!)
> > >
> > > "Mike" wrote:
> > >
> > > > try this
> > > > Sub mywordtest()
> > > >
> > > >
> > > > Dim myWord As Word.Application
> > > >
> > > > Set myWord = GetObject(, "Word.application")
> > > > myWord.Visible = True
> > > >
> > > > myWord.Documents.Open Filename:=ABFileName$, ConfirmConversions:=False, _
> > > > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
> > > > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
> > > > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> > > >
> > > > myWord.ActiveDocument.SaveAs Filename:="i:\rec.txt", FileFormat:=wdFormatText
> > > >
> > > > myWord.Selection.Find.Execute FindText:=O7C$
> > > > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > > > myWord.Selection.Delete
> > > >
> > > > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > > > myWord.Selection.Delete
> > > >
> > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > > > myWord.Selection.Delete
> > > >
> > > > myWord.ActiveDocument.Save
> > > > myWord.ActiveDocument.Close
> > > > Set myWord = Nothing
> > > > End Sub
> > > >
> > > > "GrannyM" wrote:
> > > >
> > > > > I've been doing a lot of research on the above error, but haven't found
> > > > > anything to help with my problem. I have a macro that worked great between
> > > > > Excel and Word 97, but since we switched to 2003, I keep getting the above
> > > > > error. The macro is written in excel, but opens a file in Word, and searches
> > > > > for specific information to pull into an excel spreadsheet. When the macro
> > > > > executes the "Find" command, it will give the above error and close out
> > > > > excel. Here is the section of my code causing the problem. If I rem out the
> > > > > 2 "find" lines, (which of course defeats the purpose of the macro!)
> > > > > everything else runs without problem.
> > > > >
> > > > > Public myWord As Word.Application
> > > > >
> > > > > Set myWord = GetObject(, "Word.application")
> > > > > myWord.Visible = True
> > > > >
> > > > > myWord.Documents.Open FileName:=ABFileName$, ConfirmConversions:=False,
> > > > > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="",
> > > > > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="",
> > > > > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> > > > >
> > > > > myWord.ActiveDocument.SaveAs FileName:="i:\rec.txt", FileFormat:=wdFormatText
> > > > >
> > > > > myWord.Selection.Find.Execute FindText:=O7C$
> > > > > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > > > > myWord.Selection.Delete
> > > > >
> > > > > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > > > > myWord.Selection.Delete
> > > > >
> > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > > > > myWord.Selection.Delete
> > > > >
> > > > > myWord.ActiveDocument.Save
> > > > > myWord.ActiveDocument.Close
> > > > > Set myWord = Nothing
> > > > >
> > > > > Thanks!
> > > > >

 
Reply With Quote
 
=?Utf-8?B?R3Jhbm55TQ==?=
Guest
Posts: n/a
 
      10th Apr 2007
I used a variable because the document name will depend on the date the user
needs. These are daily reports. But just to try to get this to work, I
changed it to:

Set myWord = GetObject("m:\home\daily\autobal\history\040207.rtf",
"Word.Application")

I copied the path and filename and inserted them into the Word open dialog
box and it opened the file, so I know the path is correct. But I still get
the "Filename or Classname not found during Automation Operation." I'm
putting this immediately after opening the file. I also tried to put it
before opening the file, but that didn't work either.

"Mike" wrote:

> The path needs to be like GetObject("C:\word.doc", "Word.Application"),
> not like GetObject(ABFileName$, "Word.Application"),
> If you goto properties of the word document it will give you the path
>
> "GrannyM" wrote:
>
> > I'm sorry, I'm confused. I'm setting myWord to Word.Application. Then I'm
> > opening my document. The path is in the variable ABFileName$. Are you
> > saying I need to set the path to the document after I open the document? I
> > tried to insert:
> > Set myWord = GetObject(ABFileName$, "Word.Application"), but I get "Filename
> > or Classname not found during Automation Operation. I tried inserting it
> > both before and after I actually opened the file and get the same error both
> > places.
> >
> > I think it's finding the document, because if I rem out the lines with the
> > Find command, everything else works. I'm wondering if it has something to do
> > with my references or their order. I have the following references set:
> >
> > Visual Basic for Applications
> > Microsoft Excel 11.0 Object Library
> > OLE Automation
> > Microsoft Office 11.0 Object Library
> > Microsoft DAO 2.5 Object Library
> > Microsoft Forms 2.0 Object Library
> > Microsoft Visual Basic for Applications Extensibility 5.3
> > Microsoft Word 11.0 Object Library
> > Microsoft ActiveX Data Objects 2.8 Library
> >
> > "Mike" wrote:
> >
> > > one other thing that i don't see is the path to the word document like
> > > C:\MyPath
> > > Set myWord = GetObject("C:\MyPath")
> > > Set myWord = GetObject("C:\MyPath, Word.application")
> > >
> > > "GrannyM" wrote:
> > >
> > > > Tried your code and now I get a different error. I moved this piece of code
> > > > to it's own sub, Dim'd myWord instead of using Public and called the sub from
> > > > the rest of the code. Instead of the above error, I now get "Method
> > > > 'Execute' of object 'Find' failed." So, I did a search for the value of the
> > > > variable O7C$ on the Word document to make sure it worked in Word, and it
> > > > did. Then I replaced the variable in the code with the value of the
> > > > variable, and I still received the failed message above. (At least it's
> > > > something different then before!)
> > > >
> > > > "Mike" wrote:
> > > >
> > > > > try this
> > > > > Sub mywordtest()
> > > > >
> > > > >
> > > > > Dim myWord As Word.Application
> > > > >
> > > > > Set myWord = GetObject(, "Word.application")
> > > > > myWord.Visible = True
> > > > >
> > > > > myWord.Documents.Open Filename:=ABFileName$, ConfirmConversions:=False, _
> > > > > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
> > > > > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
> > > > > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> > > > >
> > > > > myWord.ActiveDocument.SaveAs Filename:="i:\rec.txt", FileFormat:=wdFormatText
> > > > >
> > > > > myWord.Selection.Find.Execute FindText:=O7C$
> > > > > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > > > > myWord.Selection.Delete
> > > > >
> > > > > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > > > > myWord.Selection.Delete
> > > > >
> > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > > > > myWord.Selection.Delete
> > > > >
> > > > > myWord.ActiveDocument.Save
> > > > > myWord.ActiveDocument.Close
> > > > > Set myWord = Nothing
> > > > > End Sub
> > > > >
> > > > > "GrannyM" wrote:
> > > > >
> > > > > > I've been doing a lot of research on the above error, but haven't found
> > > > > > anything to help with my problem. I have a macro that worked great between
> > > > > > Excel and Word 97, but since we switched to 2003, I keep getting the above
> > > > > > error. The macro is written in excel, but opens a file in Word, and searches
> > > > > > for specific information to pull into an excel spreadsheet. When the macro
> > > > > > executes the "Find" command, it will give the above error and close out
> > > > > > excel. Here is the section of my code causing the problem. If I rem out the
> > > > > > 2 "find" lines, (which of course defeats the purpose of the macro!)
> > > > > > everything else runs without problem.
> > > > > >
> > > > > > Public myWord As Word.Application
> > > > > >
> > > > > > Set myWord = GetObject(, "Word.application")
> > > > > > myWord.Visible = True
> > > > > >
> > > > > > myWord.Documents.Open FileName:=ABFileName$, ConfirmConversions:=False,
> > > > > > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="",
> > > > > > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="",
> > > > > > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> > > > > >
> > > > > > myWord.ActiveDocument.SaveAs FileName:="i:\rec.txt", FileFormat:=wdFormatText
> > > > > >
> > > > > > myWord.Selection.Find.Execute FindText:=O7C$
> > > > > > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > > > > > myWord.Selection.Delete
> > > > > >
> > > > > > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > > > > > myWord.Selection.Delete
> > > > > >
> > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > > > > > myWord.Selection.Delete
> > > > > >
> > > > > > myWord.ActiveDocument.Save
> > > > > > myWord.ActiveDocument.Close
> > > > > > Set myWord = Nothing
> > > > > >
> > > > > > Thanks!
> > > > > >

 
Reply With Quote
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      10th Apr 2007
Try this remove the Word.Application
Set myWord = GetObject("m:\home\daily\autobal\history\040207.rtf")


"GrannyM" wrote:

> I used a variable because the document name will depend on the date the user
> needs. These are daily reports. But just to try to get this to work, I
> changed it to:
>
> Set myWord = GetObject("m:\home\daily\autobal\history\040207.rtf",
> "Word.Application")
>
> I copied the path and filename and inserted them into the Word open dialog
> box and it opened the file, so I know the path is correct. But I still get
> the "Filename or Classname not found during Automation Operation." I'm
> putting this immediately after opening the file. I also tried to put it
> before opening the file, but that didn't work either.
>
> "Mike" wrote:
>
> > The path needs to be like GetObject("C:\word.doc", "Word.Application"),
> > not like GetObject(ABFileName$, "Word.Application"),
> > If you goto properties of the word document it will give you the path
> >
> > "GrannyM" wrote:
> >
> > > I'm sorry, I'm confused. I'm setting myWord to Word.Application. Then I'm
> > > opening my document. The path is in the variable ABFileName$. Are you
> > > saying I need to set the path to the document after I open the document? I
> > > tried to insert:
> > > Set myWord = GetObject(ABFileName$, "Word.Application"), but I get "Filename
> > > or Classname not found during Automation Operation. I tried inserting it
> > > both before and after I actually opened the file and get the same error both
> > > places.
> > >
> > > I think it's finding the document, because if I rem out the lines with the
> > > Find command, everything else works. I'm wondering if it has something to do
> > > with my references or their order. I have the following references set:
> > >
> > > Visual Basic for Applications
> > > Microsoft Excel 11.0 Object Library
> > > OLE Automation
> > > Microsoft Office 11.0 Object Library
> > > Microsoft DAO 2.5 Object Library
> > > Microsoft Forms 2.0 Object Library
> > > Microsoft Visual Basic for Applications Extensibility 5.3
> > > Microsoft Word 11.0 Object Library
> > > Microsoft ActiveX Data Objects 2.8 Library
> > >
> > > "Mike" wrote:
> > >
> > > > one other thing that i don't see is the path to the word document like
> > > > C:\MyPath
> > > > Set myWord = GetObject("C:\MyPath")
> > > > Set myWord = GetObject("C:\MyPath, Word.application")
> > > >
> > > > "GrannyM" wrote:
> > > >
> > > > > Tried your code and now I get a different error. I moved this piece of code
> > > > > to it's own sub, Dim'd myWord instead of using Public and called the sub from
> > > > > the rest of the code. Instead of the above error, I now get "Method
> > > > > 'Execute' of object 'Find' failed." So, I did a search for the value of the
> > > > > variable O7C$ on the Word document to make sure it worked in Word, and it
> > > > > did. Then I replaced the variable in the code with the value of the
> > > > > variable, and I still received the failed message above. (At least it's
> > > > > something different then before!)
> > > > >
> > > > > "Mike" wrote:
> > > > >
> > > > > > try this
> > > > > > Sub mywordtest()
> > > > > >
> > > > > >
> > > > > > Dim myWord As Word.Application
> > > > > >
> > > > > > Set myWord = GetObject(, "Word.application")
> > > > > > myWord.Visible = True
> > > > > >
> > > > > > myWord.Documents.Open Filename:=ABFileName$, ConfirmConversions:=False, _
> > > > > > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
> > > > > > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
> > > > > > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> > > > > >
> > > > > > myWord.ActiveDocument.SaveAs Filename:="i:\rec.txt", FileFormat:=wdFormatText
> > > > > >
> > > > > > myWord.Selection.Find.Execute FindText:=O7C$
> > > > > > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > > > > > myWord.Selection.Delete
> > > > > >
> > > > > > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > > > > > myWord.Selection.Delete
> > > > > >
> > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > > > > > myWord.Selection.Delete
> > > > > >
> > > > > > myWord.ActiveDocument.Save
> > > > > > myWord.ActiveDocument.Close
> > > > > > Set myWord = Nothing
> > > > > > End Sub
> > > > > >
> > > > > > "GrannyM" wrote:
> > > > > >
> > > > > > > I've been doing a lot of research on the above error, but haven't found
> > > > > > > anything to help with my problem. I have a macro that worked great between
> > > > > > > Excel and Word 97, but since we switched to 2003, I keep getting the above
> > > > > > > error. The macro is written in excel, but opens a file in Word, and searches
> > > > > > > for specific information to pull into an excel spreadsheet. When the macro
> > > > > > > executes the "Find" command, it will give the above error and close out
> > > > > > > excel. Here is the section of my code causing the problem. If I rem out the
> > > > > > > 2 "find" lines, (which of course defeats the purpose of the macro!)
> > > > > > > everything else runs without problem.
> > > > > > >
> > > > > > > Public myWord As Word.Application
> > > > > > >
> > > > > > > Set myWord = GetObject(, "Word.application")
> > > > > > > myWord.Visible = True
> > > > > > >
> > > > > > > myWord.Documents.Open FileName:=ABFileName$, ConfirmConversions:=False,
> > > > > > > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="",
> > > > > > > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="",
> > > > > > > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> > > > > > >
> > > > > > > myWord.ActiveDocument.SaveAs FileName:="i:\rec.txt", FileFormat:=wdFormatText
> > > > > > >
> > > > > > > myWord.Selection.Find.Execute FindText:=O7C$
> > > > > > > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > > > > > > myWord.Selection.Delete
> > > > > > >
> > > > > > > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > > > > > > myWord.Selection.Delete
> > > > > > >
> > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > > > > > > myWord.Selection.Delete
> > > > > > >
> > > > > > > myWord.ActiveDocument.Save
> > > > > > > myWord.ActiveDocument.Close
> > > > > > > Set myWord = Nothing
> > > > > > >
> > > > > > > Thanks!
> > > > > > >

 
Reply With Quote
 
=?Utf-8?B?R3Jhbm55TQ==?=
Guest
Posts: n/a
 
      10th Apr 2007
Let me start out with saying I really appreciate all your time helping me
with this.

When I changed to the below, since myWord is dim'd as Word.Application, I
rec'd a type mismatch error. So, I dim'd myDoc as Word.Document, replaced
"myWord on your set command to myDoc, and that piece worked. However, I'm
back to "Method
'Execute' of object 'Find' failed." on myWord.Selection.Find.Execute
FindText:=O7C$. I tried replacing that line with
myDoc.Application.Selection.Find.Execute FindText:=O7C$ but rec'd the same
error. I tried replacing the O7C$ variable with the variable value. I also
went to the actual document and did a search for the value, and it did find
it in the document. However, my code still does not.

"Mike" wrote:

> Try this remove the Word.Application
> Set myWord = GetObject("m:\home\daily\autobal\history\040207.rtf")
>
>
> "GrannyM" wrote:
>
> > I used a variable because the document name will depend on the date the user
> > needs. These are daily reports. But just to try to get this to work, I
> > changed it to:
> >
> > Set myWord = GetObject("m:\home\daily\autobal\history\040207.rtf",
> > "Word.Application")
> >
> > I copied the path and filename and inserted them into the Word open dialog
> > box and it opened the file, so I know the path is correct. But I still get
> > the "Filename or Classname not found during Automation Operation." I'm
> > putting this immediately after opening the file. I also tried to put it
> > before opening the file, but that didn't work either.
> >
> > "Mike" wrote:
> >
> > > The path needs to be like GetObject("C:\word.doc", "Word.Application"),
> > > not like GetObject(ABFileName$, "Word.Application"),
> > > If you goto properties of the word document it will give you the path
> > >
> > > "GrannyM" wrote:
> > >
> > > > I'm sorry, I'm confused. I'm setting myWord to Word.Application. Then I'm
> > > > opening my document. The path is in the variable ABFileName$. Are you
> > > > saying I need to set the path to the document after I open the document? I
> > > > tried to insert:
> > > > Set myWord = GetObject(ABFileName$, "Word.Application"), but I get "Filename
> > > > or Classname not found during Automation Operation. I tried inserting it
> > > > both before and after I actually opened the file and get the same error both
> > > > places.
> > > >
> > > > I think it's finding the document, because if I rem out the lines with the
> > > > Find command, everything else works. I'm wondering if it has something to do
> > > > with my references or their order. I have the following references set:
> > > >
> > > > Visual Basic for Applications
> > > > Microsoft Excel 11.0 Object Library
> > > > OLE Automation
> > > > Microsoft Office 11.0 Object Library
> > > > Microsoft DAO 2.5 Object Library
> > > > Microsoft Forms 2.0 Object Library
> > > > Microsoft Visual Basic for Applications Extensibility 5.3
> > > > Microsoft Word 11.0 Object Library
> > > > Microsoft ActiveX Data Objects 2.8 Library
> > > >
> > > > "Mike" wrote:
> > > >
> > > > > one other thing that i don't see is the path to the word document like
> > > > > C:\MyPath
> > > > > Set myWord = GetObject("C:\MyPath")
> > > > > Set myWord = GetObject("C:\MyPath, Word.application")
> > > > >
> > > > > "GrannyM" wrote:
> > > > >
> > > > > > Tried your code and now I get a different error. I moved this piece of code
> > > > > > to it's own sub, Dim'd myWord instead of using Public and called the sub from
> > > > > > the rest of the code. Instead of the above error, I now get "Method
> > > > > > 'Execute' of object 'Find' failed." So, I did a search for the value of the
> > > > > > variable O7C$ on the Word document to make sure it worked in Word, and it
> > > > > > did. Then I replaced the variable in the code with the value of the
> > > > > > variable, and I still received the failed message above. (At least it's
> > > > > > something different then before!)
> > > > > >
> > > > > > "Mike" wrote:
> > > > > >
> > > > > > > try this
> > > > > > > Sub mywordtest()
> > > > > > >
> > > > > > >
> > > > > > > Dim myWord As Word.Application
> > > > > > >
> > > > > > > Set myWord = GetObject(, "Word.application")
> > > > > > > myWord.Visible = True
> > > > > > >
> > > > > > > myWord.Documents.Open Filename:=ABFileName$, ConfirmConversions:=False, _
> > > > > > > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
> > > > > > > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
> > > > > > > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> > > > > > >
> > > > > > > myWord.ActiveDocument.SaveAs Filename:="i:\rec.txt", FileFormat:=wdFormatText
> > > > > > >
> > > > > > > myWord.Selection.Find.Execute FindText:=O7C$
> > > > > > > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > > > > > > myWord.Selection.Delete
> > > > > > >
> > > > > > > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > > > > > > myWord.Selection.Delete
> > > > > > >
> > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > > > > > > myWord.Selection.Delete
> > > > > > >
> > > > > > > myWord.ActiveDocument.Save
> > > > > > > myWord.ActiveDocument.Close
> > > > > > > Set myWord = Nothing
> > > > > > > End Sub
> > > > > > >
> > > > > > > "GrannyM" wrote:
> > > > > > >
> > > > > > > > I've been doing a lot of research on the above error, but haven't found
> > > > > > > > anything to help with my problem. I have a macro that worked great between
> > > > > > > > Excel and Word 97, but since we switched to 2003, I keep getting the above
> > > > > > > > error. The macro is written in excel, but opens a file in Word, and searches
> > > > > > > > for specific information to pull into an excel spreadsheet. When the macro
> > > > > > > > executes the "Find" command, it will give the above error and close out
> > > > > > > > excel. Here is the section of my code causing the problem. If I rem out the
> > > > > > > > 2 "find" lines, (which of course defeats the purpose of the macro!)
> > > > > > > > everything else runs without problem.
> > > > > > > >
> > > > > > > > Public myWord As Word.Application
> > > > > > > >
> > > > > > > > Set myWord = GetObject(, "Word.application")
> > > > > > > > myWord.Visible = True
> > > > > > > >
> > > > > > > > myWord.Documents.Open FileName:=ABFileName$, ConfirmConversions:=False,
> > > > > > > > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="",
> > > > > > > > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="",
> > > > > > > > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> > > > > > > >
> > > > > > > > myWord.ActiveDocument.SaveAs FileName:="i:\rec.txt", FileFormat:=wdFormatText
> > > > > > > >
> > > > > > > > myWord.Selection.Find.Execute FindText:=O7C$
> > > > > > > > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > > > > > > > myWord.Selection.Delete
> > > > > > > >
> > > > > > > > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > > > > > > > myWord.Selection.Delete
> > > > > > > >
> > > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > > > > > > > myWord.Selection.Delete
> > > > > > > >
> > > > > > > > myWord.ActiveDocument.Save
> > > > > > > > myWord.ActiveDocument.Close
> > > > > > > > Set myWord = Nothing
> > > > > > > >
> > > > > > > > Thanks!
> > > > > > > >

 
Reply With Quote
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      10th Apr 2007
I found this code on the web see if you can do something with it
Sub OpenWordDoc()


Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objBookmark As Word.Bookmark


Set objWord = New Word.Application
objWord.Visible = True


Set objDoc = objWord.Documents.Open(Filename:="c:\docname.doc")


If objDoc.Bookmarks.Exists("BookmarkName") Then
Set objBookmark = objDoc.Bookmarks("BookmarkName")
End If


Set objBookmark = Nothing


objDoc.Close SaveChanges:=wdDoNotSaveChanges
Set objDoc = Nothing


objWord.Quit
Set objWord = Nothing


End Sub

"GrannyM" wrote:

> Let me start out with saying I really appreciate all your time helping me
> with this.
>
> When I changed to the below, since myWord is dim'd as Word.Application, I
> rec'd a type mismatch error. So, I dim'd myDoc as Word.Document, replaced
> "myWord on your set command to myDoc, and that piece worked. However, I'm
> back to "Method
> 'Execute' of object 'Find' failed." on myWord.Selection.Find.Execute
> FindText:=O7C$. I tried replacing that line with
> myDoc.Application.Selection.Find.Execute FindText:=O7C$ but rec'd the same
> error. I tried replacing the O7C$ variable with the variable value. I also
> went to the actual document and did a search for the value, and it did find
> it in the document. However, my code still does not.
>
> "Mike" wrote:
>
> > Try this remove the Word.Application
> > Set myWord = GetObject("m:\home\daily\autobal\history\040207.rtf")
> >
> >
> > "GrannyM" wrote:
> >
> > > I used a variable because the document name will depend on the date the user
> > > needs. These are daily reports. But just to try to get this to work, I
> > > changed it to:
> > >
> > > Set myWord = GetObject("m:\home\daily\autobal\history\040207.rtf",
> > > "Word.Application")
> > >
> > > I copied the path and filename and inserted them into the Word open dialog
> > > box and it opened the file, so I know the path is correct. But I still get
> > > the "Filename or Classname not found during Automation Operation." I'm
> > > putting this immediately after opening the file. I also tried to put it
> > > before opening the file, but that didn't work either.
> > >
> > > "Mike" wrote:
> > >
> > > > The path needs to be like GetObject("C:\word.doc", "Word.Application"),
> > > > not like GetObject(ABFileName$, "Word.Application"),
> > > > If you goto properties of the word document it will give you the path
> > > >
> > > > "GrannyM" wrote:
> > > >
> > > > > I'm sorry, I'm confused. I'm setting myWord to Word.Application. Then I'm
> > > > > opening my document. The path is in the variable ABFileName$. Are you
> > > > > saying I need to set the path to the document after I open the document? I
> > > > > tried to insert:
> > > > > Set myWord = GetObject(ABFileName$, "Word.Application"), but I get "Filename
> > > > > or Classname not found during Automation Operation. I tried inserting it
> > > > > both before and after I actually opened the file and get the same error both
> > > > > places.
> > > > >
> > > > > I think it's finding the document, because if I rem out the lines with the
> > > > > Find command, everything else works. I'm wondering if it has something to do
> > > > > with my references or their order. I have the following references set:
> > > > >
> > > > > Visual Basic for Applications
> > > > > Microsoft Excel 11.0 Object Library
> > > > > OLE Automation
> > > > > Microsoft Office 11.0 Object Library
> > > > > Microsoft DAO 2.5 Object Library
> > > > > Microsoft Forms 2.0 Object Library
> > > > > Microsoft Visual Basic for Applications Extensibility 5.3
> > > > > Microsoft Word 11.0 Object Library
> > > > > Microsoft ActiveX Data Objects 2.8 Library
> > > > >
> > > > > "Mike" wrote:
> > > > >
> > > > > > one other thing that i don't see is the path to the word document like
> > > > > > C:\MyPath
> > > > > > Set myWord = GetObject("C:\MyPath")
> > > > > > Set myWord = GetObject("C:\MyPath, Word.application")
> > > > > >
> > > > > > "GrannyM" wrote:
> > > > > >
> > > > > > > Tried your code and now I get a different error. I moved this piece of code
> > > > > > > to it's own sub, Dim'd myWord instead of using Public and called the sub from
> > > > > > > the rest of the code. Instead of the above error, I now get "Method
> > > > > > > 'Execute' of object 'Find' failed." So, I did a search for the value of the
> > > > > > > variable O7C$ on the Word document to make sure it worked in Word, and it
> > > > > > > did. Then I replaced the variable in the code with the value of the
> > > > > > > variable, and I still received the failed message above. (At least it's
> > > > > > > something different then before!)
> > > > > > >
> > > > > > > "Mike" wrote:
> > > > > > >
> > > > > > > > try this
> > > > > > > > Sub mywordtest()
> > > > > > > >
> > > > > > > >
> > > > > > > > Dim myWord As Word.Application
> > > > > > > >
> > > > > > > > Set myWord = GetObject(, "Word.application")
> > > > > > > > myWord.Visible = True
> > > > > > > >
> > > > > > > > myWord.Documents.Open Filename:=ABFileName$, ConfirmConversions:=False, _
> > > > > > > > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
> > > > > > > > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
> > > > > > > > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> > > > > > > >
> > > > > > > > myWord.ActiveDocument.SaveAs Filename:="i:\rec.txt", FileFormat:=wdFormatText
> > > > > > > >
> > > > > > > > myWord.Selection.Find.Execute FindText:=O7C$
> > > > > > > > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > > > > > > > myWord.Selection.Delete
> > > > > > > >
> > > > > > > > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > > > > > > > myWord.Selection.Delete
> > > > > > > >
> > > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > > > > > > > myWord.Selection.Delete
> > > > > > > >
> > > > > > > > myWord.ActiveDocument.Save
> > > > > > > > myWord.ActiveDocument.Close
> > > > > > > > Set myWord = Nothing
> > > > > > > > End Sub
> > > > > > > >
> > > > > > > > "GrannyM" wrote:
> > > > > > > >
> > > > > > > > > I've been doing a lot of research on the above error, but haven't found
> > > > > > > > > anything to help with my problem. I have a macro that worked great between
> > > > > > > > > Excel and Word 97, but since we switched to 2003, I keep getting the above
> > > > > > > > > error. The macro is written in excel, but opens a file in Word, and searches
> > > > > > > > > for specific information to pull into an excel spreadsheet. When the macro
> > > > > > > > > executes the "Find" command, it will give the above error and close out
> > > > > > > > > excel. Here is the section of my code causing the problem. If I rem out the
> > > > > > > > > 2 "find" lines, (which of course defeats the purpose of the macro!)
> > > > > > > > > everything else runs without problem.
> > > > > > > > >
> > > > > > > > > Public myWord As Word.Application
> > > > > > > > >
> > > > > > > > > Set myWord = GetObject(, "Word.application")
> > > > > > > > > myWord.Visible = True
> > > > > > > > >
> > > > > > > > > myWord.Documents.Open FileName:=ABFileName$, ConfirmConversions:=False,
> > > > > > > > > ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="",
> > > > > > > > > PasswordTemplate:="", Revert:=False, WritePasswordDocument:="",
> > > > > > > > > WritePasswordTemplate:="", Format:=wdOpenFormatAuto
> > > > > > > > >
> > > > > > > > > myWord.ActiveDocument.SaveAs FileName:="i:\rec.txt", FileFormat:=wdFormatText
> > > > > > > > >
> > > > > > > > > myWord.Selection.Find.Execute FindText:=O7C$
> > > > > > > > > myWord.Selection.MoveDown Unit:=wdLine, Count:=3
> > > > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > > > myWord.Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
> > > > > > > > > myWord.Selection.Delete
> > > > > > > > >
> > > > > > > > > myWord.Selection.Find.Execute FindText:="PlanRefNu"
> > > > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > > > myWord.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > > > > > > > > myWord.Selection.Delete
> > > > > > > > >
> > > > > > > > > myWord.Selection.HomeKey Unit:=wdLine
> > > > > > > > > myWord.Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
> > > > > > > > > myWord.Selection.Delete
> > > > > > > > >
> > > > > > > > > myWord.ActiveDocument.Save
> > > > > > > > > myWord.ActiveDocument.Close
> > > > > > > > > Set myWord = Nothing
> > > > > > > > >
> > > > > > > > > Thanks!
> > > > > > > > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
automation error the object invoked has disconnected from its clie =?Utf-8?B?dXNjaA==?= Microsoft Excel Programming 0 3rd Sep 2007 08:56 PM
Re: Automation Error: The object invoked has disconnected from its Clients onedaywhen Microsoft Excel Crashes 0 6th Feb 2004 11:37 AM
Automation Error: The object invoked has disconnected from its Clients =?Utf-8?B?SmFja2llIEJsYW5k?= Microsoft Excel Crashes 0 5th Feb 2004 02:11 PM
Automation Error (Object invoked has disconnected from its clients) sam Microsoft Windows 2000 1 6th Dec 2003 03:18 PM
Automation Error: The Object Invoked Has Disconnected from Its Clients Vaibhav Dandavate Microsoft Excel Programming 0 8th Sep 2003 04:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:43 PM.