Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Open Excel file from VB and open MACRO | Excel Discussion (Misc queries) | |||
open up an excel program with an auto open macro | Excel Programming | |||
Macro - Open Word with Excel macro | Excel Discussion (Misc queries) | |||
ASP: Open Excel File with Macro, Allow Macro to run, and then save | Excel Programming | |||
How do I get my personal macro worksheet to open whenever I open . | Excel Discussion (Misc queries) |