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 Need help w/ XL macro to open WD doc

I have worked with this for many months, and just when I think it's good it
gives me more problems! The macro is in an Excel workbook. It takes the
file name from the ActiveCell and the file path from the workbook's path,
and opens a Word document in the same folder as the workbook. All docs
listed in the workbook do exist in that folder.

Most of the time it works fine. All too often, though, it opens an instance
of Word but not the doc. Yesterday was especially bad - after running
around this circle several times, I closed all programs and went to the
folder to open the doc directly. There was a "ghost" of the doc (ghosted
icon with "~name.doc"). I checked Task Manager and yep, there was a Word
instance still running. I terminated that and killed the ghost file. But
now I'm leery of running this macro.

As additional info, I use Outlook with Word as email editor, and
occasionally open a Word toolbar to access a Word macro while composing an
email. That was my situation yesterday when the first crash happened, but
it kept happening after several Restarts and Shutdowns. If anyone has any
ideas, I'd be more than happy to hear them.

Ed

Sub FindDoc()

'Dim WD As New Word.Application
Dim WD As Object
Dim doc As String
Dim Fname As String
Dim Fpath As String

Err.Clear

' Get file path
Fpath = ThisWorkbook.Path

Sheets("Sheet1").Activate

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

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

On Error Resume Next
Set WD = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0

WD.Documents.Open doc
WD.Visible = True

Set WD = Nothing

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 2
Default Need help w/ XL macro to open WD doc

G'day "Ed" ,

You must be destroying the Word object without closing the Word
application. Thus, at the end of your excel macro, include a line like

Wordapp.Close

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Ed reckoned:

I have worked with this for many months, and just when I think it's good it
gives me more problems! The macro is in an Excel workbook. It takes the
file name from the ActiveCell and the file path from the workbook's path,
and opens a Word document in the same folder as the workbook. All docs
listed in the workbook do exist in that folder.

Most of the time it works fine. All too often, though, it opens an instance
of Word but not the doc. Yesterday was especially bad - after running
around this circle several times, I closed all programs and went to the
folder to open the doc directly. There was a "ghost" of the doc (ghosted
icon with "~name.doc"). I checked Task Manager and yep, there was a Word
instance still running. I terminated that and killed the ghost file. But
now I'm leery of running this macro.

As additional info, I use Outlook with Word as email editor, and
occasionally open a Word toolbar to access a Word macro while composing an
email. That was my situation yesterday when the first crash happened, but
it kept happening after several Restarts and Shutdowns. If anyone has any
ideas, I'd be more than happy to hear them.

Ed

Sub FindDoc()

'Dim WD As New Word.Application
Dim WD As Object
Dim doc As String
Dim Fname As String
Dim Fpath As String

Err.Clear

' Get file path
Fpath = ThisWorkbook.Path

Sheets("Sheet1").Activate

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

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

On Error Resume Next
Set WD = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0

WD.Documents.Open doc
WD.Visible = True

Set WD = Nothing

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 Need help w/ XL macro to open WD doc

Thank you, Steve. I think I tried WD.Quit, but with larger results than I
intended, if I remember correctly. (I've slept since then - sorry!) Since
Word opens a new instance for each document, when I use
Dim WD As Object
Set WD = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WD = CreateObject("Word.Application")
End If


and end with WD.Close or WD.Quit, will it affect _only_ the object I just
created, or *all* instances of the application? In other words, if I have
other docs open, will they also close or quit?
Ed

"Word Heretic" wrote in message
...
G'day "Ed" ,

You must be destroying the Word object without closing the Word
application. Thus, at the end of your excel macro, include a line like

Wordapp.Close

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Ed reckoned:

I have worked with this for many months, and just when I think it's good

it
gives me more problems! The macro is in an Excel workbook. It takes the
file name from the ActiveCell and the file path from the workbook's path,
and opens a Word document in the same folder as the workbook. All docs
listed in the workbook do exist in that folder.

Most of the time it works fine. All too often, though, it opens an

instance
of Word but not the doc. Yesterday was especially bad - after running
around this circle several times, I closed all programs and went to the
folder to open the doc directly. There was a "ghost" of the doc (ghosted
icon with "~name.doc"). I checked Task Manager and yep, there was a Word
instance still running. I terminated that and killed the ghost file.

But
now I'm leery of running this macro.

As additional info, I use Outlook with Word as email editor, and
occasionally open a Word toolbar to access a Word macro while composing

an
email. That was my situation yesterday when the first crash happened,

but
it kept happening after several Restarts and Shutdowns. If anyone has

any
ideas, I'd be more than happy to hear them.

Ed

Sub FindDoc()

'Dim WD As New Word.Application
Dim WD As Object
Dim doc As String
Dim Fname As String
Dim Fpath As String

Err.Clear

' Get file path
Fpath = ThisWorkbook.Path

Sheets("Sheet1").Activate

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

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

On Error Resume Next
Set WD = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0

WD.Documents.Open doc
WD.Visible = True

Set WD = Nothing

End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 2
Default Need help w/ XL macro to open WD doc

G'day "Ed" ,

Ideally you kill every active document in that session and close the
session. If you are acquiring an existing session you should probably
note the number of open documents, make sure the total matches that at
end, then leave trhe app running.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Ed reckoned:

Thank you, Steve. I think I tried WD.Quit, but with larger results than I
intended, if I remember correctly. (I've slept since then - sorry!) Since
Word opens a new instance for each document, when I use
Dim WD As Object
Set WD = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WD = CreateObject("Word.Application")
End If


and end with WD.Close or WD.Quit, will it affect _only_ the object I just
created, or *all* instances of the application? In other words, if I have
other docs open, will they also close or quit?
Ed

"Word Heretic" wrote in message
.. .
G'day "Ed" ,

You must be destroying the Word object without closing the Word
application. Thus, at the end of your excel macro, include a line like

Wordapp.Close

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Ed reckoned:

I have worked with this for many months, and just when I think it's good

it
gives me more problems! The macro is in an Excel workbook. It takes the
file name from the ActiveCell and the file path from the workbook's path,
and opens a Word document in the same folder as the workbook. All docs
listed in the workbook do exist in that folder.

Most of the time it works fine. All too often, though, it opens an

instance
of Word but not the doc. Yesterday was especially bad - after running
around this circle several times, I closed all programs and went to the
folder to open the doc directly. There was a "ghost" of the doc (ghosted
icon with "~name.doc"). I checked Task Manager and yep, there was a Word
instance still running. I terminated that and killed the ghost file.

But
now I'm leery of running this macro.

As additional info, I use Outlook with Word as email editor, and
occasionally open a Word toolbar to access a Word macro while composing

an
email. That was my situation yesterday when the first crash happened,

but
it kept happening after several Restarts and Shutdowns. If anyone has

any
ideas, I'd be more than happy to hear them.

Ed

Sub FindDoc()

'Dim WD As New Word.Application
Dim WD As Object
Dim doc As String
Dim Fname As String
Dim Fpath As String

Err.Clear

' Get file path
Fpath = ThisWorkbook.Path

Sheets("Sheet1").Activate

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

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

On Error Resume Next
Set WD = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0

WD.Documents.Open doc
WD.Visible = True

Set WD = Nothing

End Sub




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
Open Excel file from VB and open MACRO no1jimmyman Excel Discussion (Misc queries) 0 February 14th 11 10:10 PM
open up an excel program with an auto open macro [email protected] Excel Programming 2 July 17th 05 04:48 PM
Macro - Open Word with Excel macro Bill Excel Discussion (Misc queries) 3 May 23rd 05 11:21 PM
ASP: Open Excel File with Macro, Allow Macro to run, and then save delgados129 Excel Programming 0 March 10th 05 09:35 PM
How do I get my personal macro worksheet to open whenever I open . Claudia_R Excel Discussion (Misc queries) 3 December 9th 04 11:59 PM


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