|
-
Oct 12th, 2000, 02:16 PM
#1
Thread Starter
Lively Member
Hi,
I would like to know if a Created Object can be
destroyed or released.
Set appWord = New Word.Application
'
'
'
(I need something here that would
make sure that there is no 'instance'
of WORD Application)
0101011001000010
01101111011011100110110001101001011011100110010101110010
-
Oct 12th, 2000, 02:22 PM
#2
Set it to Nothing
Code:
Set appWord = Nothing
-
Oct 12th, 2000, 06:18 PM
#3
Thread Starter
Lively Member
FORMATTING IS CAUSING AUTOMATION ERROR!
I am applying FORMATTING to a Word document. The
first time thru the procedure everything goes ok.
But, the second time I get an Automation Error.
I always have to re-run the application so that I do
not get the automation error.
Help!
0101011001000010
01101111011011100110110001101001011011100110010101110010
-
Oct 12th, 2000, 06:24 PM
#4
Does the above method help?
-
Oct 12th, 2000, 06:29 PM
#5
Thread Starter
Lively Member
No, but it helped me narrow down the problem. Thank you.
I do not think the problem is from creating an object. Would it help if I post the code. It is not long.
0101011001000010
01101111011011100110110001101001011011100110010101110010
-
Oct 12th, 2000, 06:31 PM
#6
_______
<?>
code always helps...
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 12th, 2000, 06:38 PM
#7
Thread Starter
Lively Member
The procedure below inserts a Text file (MyFile.txt) into
a Word document (MyFile.doc), then it searches for the
word "Status" in "MyFile.doc" and re-formats the word!
Private Sub Command1_Click()
Dim appWord As Word.Application
Dim MyDoc As Document
Dim strDoc As String
If appWord Is Nothing Then
Set appWord = New Word.Application
Else
Set appWord = GetObject(, "Word.Application")
End If
With appWord
.WindowState = wdWindowStateNormal
.Visible = True
.Documents.Add
strDoc = .ActiveDocument.Name
Set MyDoc = .Documents(strDoc)
End With
With MyDoc
.Range.InsertFile App.Path & "\" & "MyFile.txt"
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Status"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Font.Size = 12
Selection.Font.Name = "Arial Narrow"
Selection.Font.Bold = wdToggle
If Selection.Font.Underline = wdUnderlineNone Then
Selection.Font.Underline = wdUnderlineSingle
Else
Selection.Font.Underline = wdUnderlineNone
End If
Selection.Font.ColorIndex = wdRed
End With
MyDoc.SaveAs App.Path & "\" & "MyFile.doc"
Set appWord = Nothing
End Sub
0101011001000010
01101111011011100110110001101001011011100110010101110010
-
Oct 12th, 2000, 07:03 PM
#8
_______
<?>
Selection.Find.ClearFormatting
What does this do?
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 12th, 2000, 07:19 PM
#9
Thread Starter
Lively Member
It serches for "Status"
finds it
Make it font size 12
underline it
change its color to red
It is doing what iit is supposed to do, but only
once.
if I hit the command1 button a second time, only then
will I get the Automation Error!
0101011001000010
01101111011011100110110001101001011011100110010101110010
-
Oct 12th, 2000, 07:26 PM
#10
_______
<?>
Yea, I've loaded it up and unfortunately I can't get past it either. Once is fine. I even added an application.quit, changed variables, closed myDoc and set it to nothing and nothing I do makes any difference. Soon as you close the vbApp and reopen it is fine again for one time only.
I will play with it a bit more.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 12th, 2000, 07:35 PM
#11
_______
<?>
Just curious...why would you want to do it again as it will just do the same thing. Have you tried it a second time with a different file or is that what you are after?
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 12th, 2000, 07:36 PM
#12
Thread Starter
Lively Member
Yes, I also tried the .close the .quit , but it didn't
solve the problem. The problem is somewhere in the Interface
between VB and Word.
Thanks for your help. I hope you'll be able
to figure it out. I tried long!!!
0101011001000010
01101111011011100110110001101001011011100110010101110010
-
Oct 12th, 2000, 07:43 PM
#13
Thread Starter
Lively Member
To : HeSaidJoe
Because I want to append to the document and search for
the same word multiple of times.
I can kill the error by On Error "LEAVE" or Resume Next
but then I would have a dead command (procedure).
0101011001000010
01101111011011100110110001101001011011100110010101110010
-
Oct 12th, 2000, 08:46 PM
#14
_______
<?>
Code:
'this works ..it was the selection.find statement
'and your reference to it.
Option Explicit
Private Sub Command1_Click()
Dim appWord As Word.Application
Dim MyDoc As Word.Document
Dim strDoc As String
Set appWord = New Word.Application
With appWord
.WindowState = wdWindowStateNormal
.Visible = True
.Documents.Add
strDoc = .ActiveDocument.Name
Set MyDoc = .Documents(strDoc)
.Selection.Find.ClearFormatting
End With
With MyDoc
.Range.InsertFile App.Path & "\" & "MyFile.txt"
With appWord.Selection.Find
.Text = "Status"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
appWord.Selection.Find.Execute
appWord.Selection.Font.Size = 12
appWord.Selection.Font.Name = "Arial Narrow"
appWord.Selection.Font.Bold = wdToggle
If appWord.Selection.Font.Underline = wdUnderlineNone Then
appWord.Selection.Font.Underline = wdUnderlineSingle
Else
appWord.Selection.Font.Underline = wdUnderlineNone
End If
appWord.Selection.Font.ColorIndex = wdRed
.SaveAs App.Path & "\" & "MyFile.doc"
.Close
End With
appWord.Quit 'you may want to take this line out
Set appWord = Nothing
Set MyDoc = Nothing
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 12th, 2000, 09:49 PM
#15
Thread Starter
Lively Member
GREAT JOB!!!
Yes, it worked. Thanks a lot.
P.S. I don't understand the logic: How can an
application be the child of a document?
0101011001000010
01101111011011100110110001101001011011100110010101110010
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|