LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Excel VBA cause Word to Crash

I didn't wade through all your code, but if this is in Excel VBA, you do not
need:

Set xlApp = GetObject(, "Excel.Application")

as you already have the Application object which refers to the current
instance.
Actually, the above code may return a completely different instance of Excel
to the one the code is running in, if multiple instances exist.

It would appear you are using late binding to Word, as you have decalred
those variables "As Object".
As such, you cannot use named constants/enums like "wdWindowStateMinimize",
but you need their numeric value, which can get from the Word VBE Immediate
window:
?wdWindowStateMinimize

What do expect this to evaluate to ?
If (missingObject1 Or missingObject2) Then

You could be more consistent with your references to objects instead of
mixing it up e.g.:
Sheets("IT - Resources & Costs").Range("A5:G51").Copy
destXL.Sheets("IT - Resources & Costs").Activate
Range("A5:G51").Select
ActiveSheet.Paste


NickHK

wrote in message
ups.com...
Hi,
I am somewhat new to vba and I am not sure if I am posting this in
the
right place but I can't seem to figure this one out or find a problem
that is similar in the postings.

My vba code runs in excel, which opens a word file, and then
subsequently has to access excel documents embedded in that word
file,
to copy some information back to the original excel document running
the code. After it is done, the code closes the document and then
word
(only if word was not previously running). The problem is that Word
seems to intermittently crash when I am trying to close the document
or the application.


I have thought of several reasons this may be happening. My primary
concern is this though: I do not know how change the focus/close from
the last embedded excel document once it has been activated, so I go
from that to just close the document. I wonder if what causes Word to
crash is that it is trying to hold on to the OLE connections of the
embedded excel files and takes time to release them. I had tried to
deal with this by putting a Sleep break in the program, but it still
seems to crash 1 out of about 10 times.


I have attached the code below:
========CODE============
Dim SAFileName As String
Dim strFilter As String


Dim wdApp As Object
Dim wdDoc As Object
Dim wdRunning As Boolean

--------- CUT ----


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel and Word crash when I try to add a UserForm interrogativo Excel Programming 4 August 21st 17 03:49 PM
Word and Excel crash when I try to open a folder to get to a file DGD41 Excel Discussion (Misc queries) 7 April 15th 06 09:14 PM
excel and word crash Ijaz Excel Worksheet Functions 1 April 15th 06 04:35 AM
VBE causes excel and word to crash when closed Janwillem van Dijk[_2_] Excel Programming 4 September 6th 05 08:45 PM
Excel VBA printing to MS Word cause MS Word to crash, why? alruff Excel Programming 0 October 4th 04 09:57 PM


All times are GMT +1. The time now is 06:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"