Obtaining Active Document Name from WORD for Excel procedure

  • Thread starter Thread starter Tim Childs
  • Start date Start date
T

Tim Childs

Hi

I want to return the name of the active document from WORD from within an
Excel macro i.e. the macro in the workbook interrogates WORD to find the
name of the currently active document.

Any help gratefully received

Thanks

Tim
 
Try the following:

Dim WordApp As Object
Set WordApp = GetObject(, "Word.Application")
If Not WordApp.ActiveDocument Is Nothing Then
MsgBox "Active Document: " & WordApp.ActiveDocument.FullName
End If

Change FullName to Name if you don't want the path information.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Tim

No error checking or fancy stuff, but here is the theory. Uses early
binding so a reference to the word object lirary with be necessary via
tools>references in the VBE

Sub getWordDocName()
Dim wd As New Word.Application
Dim wddoc As Word.Document
Set wd = Word.Application
Set wddoc = wd.ActiveDocument
MsgBox wddoc.Name
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
www.nickhodge.co.uk
(e-mail address removed)
 
Chip, Nick

Many thanks for the response including the reference in the Tools Library -
I would not have spotted this otherwise

best wishes

Tim
 
Tim,
Bear in mind that if you have more than one instance of Word, GetObject will
you one instance essentially randomly.
So it would depend if this is a concern for you.

NickHK
 
Back
Top