Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

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

Avatar of J2F
J2FFlag for United States of America asked on
Office ProductivitySpreadsheetsWord Processors
2 Comments1 Solution598 ViewsLast Modified:
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]

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.

Tonkawa Jingles
Avatar of dsacker
dsackerFlag of United States of America imageContract ERP Admin/Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answers