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: 9
Default Excel using Word --- Object is not responding

Hi Alan,

You shouldn't be using functions for these tasks. They are meant to be used
when you perform a calculation and want your routine to output something. In
this case, a macro would be better suited for the tasks. Also, you are trying
to create (get) an instance of Word in two separate places in your code. It'd
be simpler if this task were in the same macro.

The On Error Resume Next feature should check only for the error you expect,
not for every error. If something else goes wrong, besides not finding an
open Word application, you won't know it.

Finally, I don't recommend getting to the Document object through the Word
application. You should create an instance of a Document object and work with
it.

Here is the code I 'd use:

Option Explicit
Public Sub CreateWordApplication()
Dim wdApp As Object
Dim doc As Object

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number = 429 Then 'Catching run-time error '429': ActiveX component
can't create object
Set wdApp = CreateObject("Word.Application")
Err.Clear
End If

wdApp.Visible = True
wdApp.Activate

Set doc = wdApp.Documents.Add
'TODO: Write the instructions for the Word document.
'Consider using a separate macro for this task.

Set wdApp = Nothing
Set doc = Nothing

End Sub

--
Carlos Mallen


"Alan" wrote:

I am using VBA in Excel to create a Word document containing tables
from a spreadsheet. However, I often get an error message that pops
up: "The object is not responding because the source application may
be busy." When I stop the program at that point, I get the VBA error:
"Automation error - Call was rejected by callee."

Here is how I start Word:

Function StartWord() As Boolean
StartWord = False
' Try to open an existing instance of Word
On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
On Error GoTo 0
' If Word is not started, start a new instance
If WordApp Is Nothing Then
Set WordApp = CreateObject("Word.Application")
End If
WordApp.Visible = False
StartWord = True
End Function

Here are the relevant code snippets that use Word:

' Start the Word application
If Not StartWord() Then
MsgBox "Unable to start Microsoft Word", vbCritical,
"Microsoft Word Error"
Exit Function
End If
' Add a new Word document
WordApp.Application.ScreenUpdating = False
WordApp.Documents.Add
'Set DataTableWS = DataWB.Sheets("table")
' Set up Word document properties
With WordApp.ActiveDocument.PageSetup
.Orientation = wdOrientPortrait
.TopMargin = 20
.BottomMargin = 20
.LeftMargin = 40
.RightMargin = 40
.PageWidth = 700
.PageHeight = 800
.Gutter = 0
End With

It consistently bombs on the statement:

With WordApp.ActiveDocument.PageSetup

Can anyone provide advice on this problem?

Thanks, Alan








 
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 object linked to word will not add sums in word Robin Excel Discussion (Misc queries) 0 March 31st 09 11:10 PM
Excel Object in Word Document MSweetG222 Excel Programming 0 February 21st 07 04:56 PM
windows excel &word 2003 pro save as command not responding Armando Robles V. Excel Discussion (Misc queries) 4 April 15th 06 10:37 PM
can't save anything in excel or word .... i get "not responding" astat101 Excel Discussion (Misc queries) 1 April 12th 06 07:08 PM
word object in excel daron tan Excel Programming 0 September 21st 05 10:27 AM


All times are GMT +1. The time now is 06:03 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"