|
[x]
Posted via EE Mobile
|
|
| Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
|
|
|
|
Asked by AmeriFill in Microsoft Word, Visual Basic Programming
Dear Expert:
I have a code that is activated upon clicking a macro called "Email" (see below). This macro is to save the document with a filename based upon the ActiveDocument bookmark "DocFileName" into a specified folder and then send out an email to specified recipients in Outlook. The code below works fine if you are the originator of the document; however, if you are the recipient of the email and subsequently try to activate the same type of "Email" macro, you receive the error:
"Document is currently in use. Try again later." and "Run-time error '4198': Command Failed.
The highlighted command in the macro which indicates the failure is:
"Application.ActiveDocumen
t.SaveAs target & fileName"
Thanks for your help!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
|
Sub Email()
Dim fld As Field
Dim target As String
Dim fileName As String
Dim file As String
file = Application.ActiveDocument.Name
target = "C:\Foldername\"
target1 = "<file://" & "C:\Foldername" & ">"
fileName = ActiveDocument.Bookmarks("DocFileName").Range
Application.ActiveDocument.SaveAs target & fileName
Dim ol As Object 'outlook application object
Set ol = CreateObject("Outlook.Application") 'create an instance of the outlook application
Dim olItem As Object 'outlook mail object
Set olItem = ol.CreateItem(0)
With olItem
.To = "email1@somewhere.com"
'.CC = "email2@somewhere.com"
.Subject = "Review of " + fileName
.Body = "Please immediately evaluate: " + fileName
.Display 'show the email (user need to click the send button)
'.Send 'sends the email (Outlook security prompt will appear)
End With
'clear the outlook mail object
Set olItem = Nothing
'clear the outlook application object
Set ol = Nothing
End Sub
|
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625