rdy123 rdy
asked on
macro for closing opened workbook
Hi,
i have a macro as below, it opens the word document as pastes in outlook. i want to close whole word document without saving. i have written this as well,but i am getting a popup "would you like to keep the last item copied? if so,it may take us a bit longer to exit.
YES NO" it should be No. i have used wd.quit but the document is not closing. how I can close the document without leaving this blank application window?
please suggest.
Sub emailFromDoc(fileLocation As String, x As Variant, y As Variant)
Dim wd As Object, editor As Object
Dim doc As Object
Dim Omail As Object
Dim objOutlook As Object
Dim CompanyName As String
On Error Resume Next
Set wd = GetObject(, "Word.Application")
Set doc = wd.Documents("Followup1.do cx")
On Error GoTo 0
If wd Is Nothing Then
Set wd = CreateObject("Word.Applica tion")
Set doc = wd.Documents.Open("fileLoc ation")
wd.Visible = True
End If
doc.Content.Copy
doc.Close savechanges:=False
Set objOutlook = CreateObject("Outlook.Appl ication")
Set Omail = objOutlook.CreateItem(olMa ilItem)
With Omail
.HTMLBody = Replace(.HTMLBody, "<<Company1>>" , CompanyName)
Set editor = .GetInspector.WordEditor
editor.Content.Paste
.Display
wd.Quit
Set wd = Nothing
End With
End Sub
i have a macro as below, it opens the word document as pastes in outlook. i want to close whole word document without saving. i have written this as well,but i am getting a popup "would you like to keep the last item copied? if so,it may take us a bit longer to exit.
YES NO" it should be No. i have used wd.quit but the document is not closing. how I can close the document without leaving this blank application window?
please suggest.
Sub emailFromDoc(fileLocation As String, x As Variant, y As Variant)
Dim wd As Object, editor As Object
Dim doc As Object
Dim Omail As Object
Dim objOutlook As Object
Dim CompanyName As String
On Error Resume Next
Set wd = GetObject(, "Word.Application")
Set doc = wd.Documents("Followup1.do
On Error GoTo 0
If wd Is Nothing Then
Set wd = CreateObject("Word.Applica
Set doc = wd.Documents.Open("fileLoc
wd.Visible = True
End If
doc.Content.Copy
doc.Close savechanges:=False
Set objOutlook = CreateObject("Outlook.Appl
Set Omail = objOutlook.CreateItem(olMa
With Omail
.HTMLBody = Replace(.HTMLBody, "<<Company1>>"
Set editor = .GetInspector.WordEditor
editor.Content.Paste
.Display
wd.Quit
Set wd = Nothing
End With
End Sub
ASKER
Thank you,but i am still getting the same pop up,i don't want to get that pop up and it should close the whole word document. please suggest.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
still getting the same,no idea why..
then try
with reference to ms.forms
with reference to ms.forms
Sub emailFromDoc(fileLocation As String, x As Variant, y As Variant)
Dim wd As Object, editor As Object
Dim doc As Object
Dim Omail As Object
Dim objOutlook As Object
Dim CompanyName As String
On Error Resume Next
Set wd = GetObject(, "Word.Application")
Set doc = wd.Documents("Followup1.docx")
On Error GoTo 0
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
Set doc = wd.Documents.Open("fileLocation")
wd.Visible = True
End If
doc.Content.Copy
wd.Visible = False
Set objOutlook = CreateObject("Outlook.Application")
Set Omail = objOutlook.CreateItem(olMailItem)
With Omail
.HTMLBody = Replace(.HTMLBody, "<<Company1>>", CompanyName)
Set editor = .GetInspector.WordEditor
editor.Content.Paste
.Display
End With
Dim MyData As DataObject
Set MyData = New DataObject
MyData.SetText ""
MyData.PutInClipboard
doc.Close
doc.Close savechanges:=False
wd.Quit
Set wd = Nothing
End Sub
ASKER
its my excel issue,its working,thank you
pls try
Open in new window
Regards