Link to home
Start Free TrialLog in
Avatar of J2F
J2FFlag for United States of America

asked on

Need help with Excel VBA code to close a Word document.

I'm using 2010 versions of Excel and Word.
When my Excel workbook, TT.xlsm, is opened, Workbook_Open() calls a local Sub, OpenAWordDocument, which, in turn, opens a Word document.

Sub OpenAWordDocument(Optional ByVal DocName As String = "", Optional ByVal DocPath As String = "")
Dim objWord As Object
  If Len(Trim(DocName)) = 0 Then
    DocName = "Word Document.docx"
  End If
  If Len(Trim(DocPath)) = 0 Then
    DocPath = "D:\Documentation"
  End If
  If Right(DocPath, 1) <> Application.PathSeparator Then
    DocPath = DocPath & Application.PathSeparator
  End If
'Open an existing Word Document from Excel
  Set objWord = CreateObject("Word.Application")
  With objWord
    .Visible = True
    .Documents.Open DocPath & DocName
  End With
  Set objWord = Nothing
End Sub[/indent][/indent][/indent]

Open in new window


I would appreciate some help developing a procedure to call from Workbook_BeforeClose() which will Save and Close the Word document without requiring operator intervention.

Thanks,
Tonkawa Jingles
ASKER CERTIFIED SOLUTION
Avatar of dsacker
dsacker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of J2F

ASKER

Works like a charm!