Close a Excel Workbook when close a userform in Outlook

  • Thread starter Thread starter lars.oyangen
  • Start date Start date
L

lars.oyangen

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
Set objXL = GetObject(, "Excel.Application")

x = objXL.Workbooks.Application.ActiveWorkbook.Name

If x = "Prosjekt.xls" Then
objXL.x.Close savechanges:=True ' ?????????
End If

End Sub

Need help!
 
You are trying to call the Close method on the Name property of the
workbook. Try getting the workbook as an object and calling its Close
method.
 
Thanks, this works:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)

Dim XLObject As Object
Set XLObject = GetObject("H:\Outlook\Prosjekt.xls")
XLObject.Close SaveChanges:=True

End Sub
 
Back
Top