Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Why doesn't "Resume Next" work?

I wrote a macro in Excel 2000 VBA to open a document in Word 2000. I used
code from the GetObject Help file to check if Word is already active. But
the code stops on an error generated by using GetObject - "Active X
component can't create object." On Error Resume Next does not drop the code
through to the next line.

Can someone explain what I have wrong?
Ed

Sub FindDoc()

Dim WD As Object
Dim doc As String
Dim Fname As String
Dim Fpath As String

' Get file path
Fpath = ThisWorkbook.Path

Sheets("Sheet1").Activate

' Get doc number from list page
Fname = ActiveCell.Text

' Open doc
On Error Resume Next
' **ERROR NEXT LINE**
Set WD = GetObject(, "Word.Application")
MsgBox Err.Number
If Err.Number < 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0

doc = Fpath & "\" & Fname & ".doc"

WD.Documents.Open doc
WD.Visible = True

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 5,302
Default Why doesn't "Resume Next" work?

Hi Ed,

Do you have the 'Break on all errors' option checked?

Tools | Options | General Tab


---
Regards,
Norman



"Ed" wrote in message
...
I wrote a macro in Excel 2000 VBA to open a document in Word 2000. I used
code from the GetObject Help file to check if Word is already active. But
the code stops on an error generated by using GetObject - "Active X
component can't create object." On Error Resume Next does not drop the
code
through to the next line.

Can someone explain what I have wrong?
Ed

Sub FindDoc()

Dim WD As Object
Dim doc As String
Dim Fname As String
Dim Fpath As String

' Get file path
Fpath = ThisWorkbook.Path

Sheets("Sheet1").Activate

' Get doc number from list page
Fname = ActiveCell.Text

' Open doc
On Error Resume Next
' **ERROR NEXT LINE**
Set WD = GetObject(, "Word.Application")
MsgBox Err.Number
If Err.Number < 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0

doc = Fpath & "\" & Fname & ".doc"

WD.Documents.Open doc
WD.Visible = True

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Why doesn't "Resume Next" work?

Yes.

"Norman Jones" wrote in message
...
Hi Ed,

Do you have the 'Break on all errors' option checked?

Tools | Options | General Tab


---
Regards,
Norman



"Ed" wrote in message
...
I wrote a macro in Excel 2000 VBA to open a document in Word 2000. I

used
code from the GetObject Help file to check if Word is already active.

But
the code stops on an error generated by using GetObject - "Active X
component can't create object." On Error Resume Next does not drop the
code
through to the next line.

Can someone explain what I have wrong?
Ed

Sub FindDoc()

Dim WD As Object
Dim doc As String
Dim Fname As String
Dim Fpath As String

' Get file path
Fpath = ThisWorkbook.Path

Sheets("Sheet1").Activate

' Get doc number from list page
Fname = ActiveCell.Text

' Open doc
On Error Resume Next
' **ERROR NEXT LINE**
Set WD = GetObject(, "Word.Application")
MsgBox Err.Number
If Err.Number < 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0

doc = Fpath & "\" & Fname & ".doc"

WD.Documents.Open doc
WD.Visible = True

End Sub






  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 27,285
Default Why doesn't "Resume Next" work?

Just to remove any doubt,

then change it to Break on Unhandled errors.

--
Regards,
Tom Ogilvy

"Ed" wrote in message
...
Yes.

"Norman Jones" wrote in message
...
Hi Ed,

Do you have the 'Break on all errors' option checked?

Tools | Options | General Tab


---
Regards,
Norman



"Ed" wrote in message
...
I wrote a macro in Excel 2000 VBA to open a document in Word 2000. I

used
code from the GetObject Help file to check if Word is already active.

But
the code stops on an error generated by using GetObject - "Active X
component can't create object." On Error Resume Next does not drop

the
code
through to the next line.

Can someone explain what I have wrong?
Ed

Sub FindDoc()

Dim WD As Object
Dim doc As String
Dim Fname As String
Dim Fpath As String

' Get file path
Fpath = ThisWorkbook.Path

Sheets("Sheet1").Activate

' Get doc number from list page
Fname = ActiveCell.Text

' Open doc
On Error Resume Next
' **ERROR NEXT LINE**
Set WD = GetObject(, "Word.Application")
MsgBox Err.Number
If Err.Number < 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0

doc = Fpath & "\" & Fname & ".doc"

WD.Documents.Open doc
WD.Visible = True

End Sub








  #5   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Why doesn't "Resume Next" work?

As usual, Tom, that did it! I guess I had the mistaken assumption that On
Error Resume Next would override any setting to break on an error. I assume
this is an application setting, and not specific to an individual file or
template?

Ed

"Tom Ogilvy" wrote in message
...
Just to remove any doubt,

then change it to Break on Unhandled errors.

--
Regards,
Tom Ogilvy

"Ed" wrote in message
...
Yes.

"Norman Jones" wrote in message
...
Hi Ed,

Do you have the 'Break on all errors' option checked?

Tools | Options | General Tab


---
Regards,
Norman



"Ed" wrote in message
...
I wrote a macro in Excel 2000 VBA to open a document in Word 2000. I

used
code from the GetObject Help file to check if Word is already

active.
But
the code stops on an error generated by using GetObject - "Active X
component can't create object." On Error Resume Next does not drop

the
code
through to the next line.

Can someone explain what I have wrong?
Ed

Sub FindDoc()

Dim WD As Object
Dim doc As String
Dim Fname As String
Dim Fpath As String

' Get file path
Fpath = ThisWorkbook.Path

Sheets("Sheet1").Activate

' Get doc number from list page
Fname = ActiveCell.Text

' Open doc
On Error Resume Next
' **ERROR NEXT LINE**
Set WD = GetObject(, "Word.Application")
MsgBox Err.Number
If Err.Number < 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0

doc = Fpath & "\" & Fname & ".doc"

WD.Documents.Open doc
WD.Visible = True

End Sub












  #6   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 27,285
Default Why doesn't "Resume Next" work?

Yes, it is an application setting as I recall.

--
Regards,
Tom Ogilvy

"Ed" wrote in message
...
As usual, Tom, that did it! I guess I had the mistaken assumption that On
Error Resume Next would override any setting to break on an error. I

assume
this is an application setting, and not specific to an individual file or
template?

Ed

"Tom Ogilvy" wrote in message
...
Just to remove any doubt,

then change it to Break on Unhandled errors.

--
Regards,
Tom Ogilvy

"Ed" wrote in message
...
Yes.

"Norman Jones" wrote in message
...
Hi Ed,

Do you have the 'Break on all errors' option checked?

Tools | Options | General Tab


---
Regards,
Norman



"Ed" wrote in message
...
I wrote a macro in Excel 2000 VBA to open a document in Word 2000.

I
used
code from the GetObject Help file to check if Word is already

active.
But
the code stops on an error generated by using GetObject - "Active

X
component can't create object." On Error Resume Next does not

drop
the
code
through to the next line.

Can someone explain what I have wrong?
Ed

Sub FindDoc()

Dim WD As Object
Dim doc As String
Dim Fname As String
Dim Fpath As String

' Get file path
Fpath = ThisWorkbook.Path

Sheets("Sheet1").Activate

' Get doc number from list page
Fname = ActiveCell.Text

' Open doc
On Error Resume Next
' **ERROR NEXT LINE**
Set WD = GetObject(, "Word.Application")
MsgBox Err.Number
If Err.Number < 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0

doc = Fpath & "\" & Fname & ".doc"

WD.Documents.Open doc
WD.Visible = True

End Sub












  #7   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 22
Default Why doesn't "Resume Next" work?


Ed skrev:

I wrote a macro in Excel 2000 VBA to open a document in Word 2000. I used
code from the GetObject Help file to check if Word is already active. But
the code stops on an error generated by using GetObject - "Active X
component can't create object." On Error Resume Next does not drop the code
through to the next line.

Can someone explain what I have wrong?
Ed


Hi Ed,

Are you sure the error emerges where you think, and not on the
"WD.Documents.Open doc" (which is out of the On Error Resume Next
scope)?

/impslayer

  #8   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Why doesn't "Resume Next" work?

When the error occurs when the macro is run, the Debug / Exit alert box pops
up, the screen flips to the VBE, and the line highlighted in yellow is the
GetObject line. The WD.Documents.Open line works fine if an instance of
Word is already available. If not, I get the error.

Ed

"impslayer" wrote in message
oups.com...

Ed skrev:

I wrote a macro in Excel 2000 VBA to open a document in Word 2000. I

used
code from the GetObject Help file to check if Word is already active.

But
the code stops on an error generated by using GetObject - "Active X
component can't create object." On Error Resume Next does not drop the

code
through to the next line.

Can someone explain what I have wrong?
Ed


Hi Ed,

Are you sure the error emerges where you think, and not on the
"WD.Documents.Open doc" (which is out of the On Error Resume Next
scope)?

/impslayer



Reply
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
pictures to work with "data" "sort" option arad Excel Discussion (Misc queries) 1 April 18th 06 09:15 PM
"on error resume next" NOT working... Chris M Excel Programming 2 July 13th 05 10:30 PM
how to stop "On error resume next" ? Alex St-Pierre Excel Programming 0 February 11th 05 02:03 PM
Problem with "On error resume next" with "custom VLookup" Factivator Excel Programming 3 July 20th 04 04:42 PM
"On Error Resume Next" Question Jim[_26_] Excel Programming 1 September 20th 03 07:38 PM


All times are GMT +1. The time now is 02:49 AM.

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"