A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Attach file to Current Email



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 24th 08, 05:03 PM posted to microsoft.public.outlook.program_vba
Ayth
external usenet poster
 
Posts: 5
Default Attach file to Current Email

Hello,

Can someone point me in the right direction? Or some sample code that
would do the following:

1. Save the current active document in Word.
2. Attach it to the current email
3. Save the email since it will be in "Edit Mode".

I can do number one without a problem, but it's the second portion
that's giving me problems. I know I'll have to use GetInspector to use
the current item, but I'm having troubles. Thanks.

Cheers,

Darrin
Ads
  #2  
Old June 24th 08, 05:39 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Attach file to Current Email

Application.ActiveInspector.CurrentItem.Attachment s.Add "c:\my document.doc"

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Ayth" wrote in message
...
Hello,

Can someone point me in the right direction? Or some sample code that
would do the following:

1. Save the current active document in Word.
2. Attach it to the current email
3. Save the email since it will be in "Edit Mode".

I can do number one without a problem, but it's the second portion
that's giving me problems. I know I'll have to use GetInspector to use
the current item, but I'm having troubles. Thanks.

Cheers,

Darrin



  #3  
Old June 24th 08, 05:53 PM posted to microsoft.public.outlook.program_vba
Ayth
external usenet poster
 
Posts: 5
Default Attach file to Current Email

On Jun 24, 1:39*pm, "Dmitry Streblechenko" wrote:
Application.ActiveInspector.CurrentItem.Attachment s.Add "c:\my document.doc"

--
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy *- Outlook, CDO
and MAPI Developer Tool
-"Ayth" wrote in message

...

Hello,


Can someone point me in the right direction? Or some sample code that
would do the following:


1. Save the current active document in Word.
2. Attach it to the current email
3. Save the email since it will be in "Edit Mode".


I can do number one without a problem, but it's the second portion
that's giving me problems. I know I'll have to use GetInspector to use
the current item, but I'm having troubles. Thanks.


Cheers,


Darrin


That was what I was starting to get at but it's still not working for
me. Here is my code so far:

Sub Save_Attach()
Dim objMSWord As Word.Application
Dim itmWord As Word.Document
Dim objOutlook As Outlook.Application
Dim objInspector As Outlook.Inspector
Dim objItem As Object 'Allow any Outlook item type.
Dim itmAttach
Dim objAttachments As Outlook.Attachments

itmAttach = Environ("userprofile") & "\Desktop\Sticky.doc"
' Convert it to a string.
itmAttach = StrConv(itmOpen, vbProperCase)
' The ActiveInspector is the currently open item.
'MsgBox itmAttach
Set objInspector = objOutlook.ActiveInspector
Set objItem = objInspector.CurrentItem
Set objAttachments = objItem.Attachments
Set objMSWord = Word.Application
Set itmWord = objMSWord.ActiveDocument
itmWord.Save
objAttachments.Add "C:\Documents and Settings\dhenshaw\desktop
\sticky.doc"
End Sub

As you can see I'm pulling the environmental variable userprofile,
tacking on the "\Desktop\sticky.doc" to it. That works fine in another
macro I created to open that document.

If I uncomment the MsgBox itmAttach I get a blank message box, so it's
not pulling that variable right. However, even if I hard code the file
it's not working for me.

A little background info on this. I created one macro which does the
following:

1. Programatically calls the Edit Edit Message command.
2. Then opens this sticky.doc which is located on the desktop.

Then this second button will need to do the steps I outline above. Can
anyone see the problem with my code? Thanks.
  #4  
Old June 24th 08, 06:37 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Attach file to Current Email

So the problem is that you cannot figure out where the Woird document is
stored, right?
You might want to ask that question in one of the Word newsgroups, but I can
imagine that Word document exposes the file name property explicitly.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Ayth" wrote in message
...
On Jun 24, 1:39 pm, "Dmitry Streblechenko" wrote:
Application.ActiveInspector.CurrentItem.Attachment s.Add "c:\my
document.doc"

--
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-"Ayth" wrote in message

...

Hello,


Can someone point me in the right direction? Or some sample code that
would do the following:


1. Save the current active document in Word.
2. Attach it to the current email
3. Save the email since it will be in "Edit Mode".


I can do number one without a problem, but it's the second portion
that's giving me problems. I know I'll have to use GetInspector to use
the current item, but I'm having troubles. Thanks.


Cheers,


Darrin


That was what I was starting to get at but it's still not working for
me. Here is my code so far:

Sub Save_Attach()
Dim objMSWord As Word.Application
Dim itmWord As Word.Document
Dim objOutlook As Outlook.Application
Dim objInspector As Outlook.Inspector
Dim objItem As Object 'Allow any Outlook item type.
Dim itmAttach
Dim objAttachments As Outlook.Attachments

itmAttach = Environ("userprofile") & "\Desktop\Sticky.doc"
' Convert it to a string.
itmAttach = StrConv(itmOpen, vbProperCase)
' The ActiveInspector is the currently open item.
'MsgBox itmAttach
Set objInspector = objOutlook.ActiveInspector
Set objItem = objInspector.CurrentItem
Set objAttachments = objItem.Attachments
Set objMSWord = Word.Application
Set itmWord = objMSWord.ActiveDocument
itmWord.Save
objAttachments.Add "C:\Documents and Settings\dhenshaw\desktop
\sticky.doc"
End Sub

As you can see I'm pulling the environmental variable userprofile,
tacking on the "\Desktop\sticky.doc" to it. That works fine in another
macro I created to open that document.

If I uncomment the MsgBox itmAttach I get a blank message box, so it's
not pulling that variable right. However, even if I hard code the file
it's not working for me.

A little background info on this. I created one macro which does the
following:

1. Programatically calls the Edit Edit Message command.
2. Then opens this sticky.doc which is located on the desktop.

Then this second button will need to do the steps I outline above. Can
anyone see the problem with my code? Thanks.


  #5  
Old June 24th 08, 07:29 PM posted to microsoft.public.outlook.program_vba
Ayth
external usenet poster
 
Posts: 5
Default Attach file to Current Email

On Jun 24, 2:37*pm, "Dmitry Streblechenko" wrote:
So the problem is that you cannot figure out where the Woird document is
stored, right?
You might want to ask that question in one of the Word newsgroups, but I can
imagine that Word document exposes the file name property explicitly.

--
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy *- Outlook, CDO
and MAPI Developer Tool
-"Ayth" wrote in message

...
On Jun 24, 1:39 pm, "Dmitry Streblechenko" wrote:



Application.ActiveInspector.CurrentItem.Attachment s.Add "c:\my
document.doc"


--
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-"Ayth" wrote in message


...


Hello,


Can someone point me in the right direction? Or some sample code that
would do the following:


1. Save the current active document in Word.
2. Attach it to the current email
3. Save the email since it will be in "Edit Mode".


I can do number one without a problem, but it's the second portion
that's giving me problems. I know I'll have to use GetInspector to use
the current item, but I'm having troubles. Thanks.


Cheers,


Darrin


That was what I was starting to get at but it's still not working for
me. Here is my code so far:

Sub Save_Attach()
* * Dim objMSWord As Word.Application
* * Dim itmWord As Word.Document
* * Dim objOutlook As Outlook.Application
* * Dim objInspector As Outlook.Inspector
* * Dim objItem As Object 'Allow any Outlook item type.
* * Dim itmAttach
* * Dim objAttachments As Outlook.Attachments

* * itmAttach = Environ("userprofile") & "\Desktop\Sticky.doc"
* * ' Convert it to a string.
* * itmAttach = StrConv(itmOpen, vbProperCase)
* * ' The ActiveInspector is the currently open item.
* * 'MsgBox itmAttach
* * Set objInspector = objOutlook.ActiveInspector
* * Set objItem = objInspector.CurrentItem
* * Set objAttachments = objItem.Attachments
* * Set objMSWord = Word.Application
* * Set itmWord = objMSWord.ActiveDocument
* * itmWord.Save
* * objAttachments.Add "C:\Documents and Settings\dhenshaw\desktop
\sticky.doc"
End Sub

As you can see I'm pulling the environmental variable userprofile,
tacking on the "\Desktop\sticky.doc" to it. That works fine in another
macro I created to open that document.

If I uncomment the MsgBox itmAttach I get a blank message box, so it's
not pulling that variable right. However, even if I hard code the file
it's not working for me.

A little background info on this. I created one macro which does the
following:

1. Programatically calls the Edit Edit Message command.
2. Then opens this sticky.doc which is located on the desktop.

Then this second button will need to do the steps I outline above. Can
anyone see the problem with my code? Thanks.


I wish, that might be easier. No the word document is stored
statically in one spot. The problem is that the attachment does not
appear in the email. The saving of the word document works fine, once
you add the reference to the Microsoft Word 11 or 12 library,
depending on the version. I'm thinking the problem might be that this
is not an email waiting to be sent. This is an email already received,
that's been opened, set into what I call "Edit Mode"(clicking Edit
Edit Message).

But then I took out the code that deals with Word and tried to attach
the file to a new email, and it still doesn't work. No error message,
just doesn't work for me. Thanks.
  #6  
Old June 24th 08, 09:43 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Attach file to Current Email

How many messages do you have when te hcode is executed?
Does it work if you explicitly create a new message?

Set objItem = objOutlook.CreateItem(0)
Set objAttachments = objItem.Attachments
objAttachments.Add "C:\Documents and
Settings\dhenshaw\desktop\sticky.doc"
objItem.Display


--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Ayth" wrote in message
...
On Jun 24, 2:37 pm, "Dmitry Streblechenko" wrote:
So the problem is that you cannot figure out where the Woird document is
stored, right?
You might want to ask that question in one of the Word newsgroups, but I
can
imagine that Word document exposes the file name property explicitly.

--
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-"Ayth" wrote in message

...
On Jun 24, 1:39 pm, "Dmitry Streblechenko" wrote:



Application.ActiveInspector.CurrentItem.Attachment s.Add "c:\my
document.doc"


--
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-"Ayth" wrote in message


...


Hello,


Can someone point me in the right direction? Or some sample code that
would do the following:


1. Save the current active document in Word.
2. Attach it to the current email
3. Save the email since it will be in "Edit Mode".


I can do number one without a problem, but it's the second portion
that's giving me problems. I know I'll have to use GetInspector to use
the current item, but I'm having troubles. Thanks.


Cheers,


Darrin


That was what I was starting to get at but it's still not working for
me. Here is my code so far:

Sub Save_Attach()
Dim objMSWord As Word.Application
Dim itmWord As Word.Document
Dim objOutlook As Outlook.Application
Dim objInspector As Outlook.Inspector
Dim objItem As Object 'Allow any Outlook item type.
Dim itmAttach
Dim objAttachments As Outlook.Attachments

itmAttach = Environ("userprofile") & "\Desktop\Sticky.doc"
' Convert it to a string.
itmAttach = StrConv(itmOpen, vbProperCase)
' The ActiveInspector is the currently open item.
'MsgBox itmAttach
Set objInspector = objOutlook.ActiveInspector
Set objItem = objInspector.CurrentItem
Set objAttachments = objItem.Attachments
Set objMSWord = Word.Application
Set itmWord = objMSWord.ActiveDocument
itmWord.Save
objAttachments.Add "C:\Documents and Settings\dhenshaw\desktop
\sticky.doc"
End Sub

As you can see I'm pulling the environmental variable userprofile,
tacking on the "\Desktop\sticky.doc" to it. That works fine in another
macro I created to open that document.

If I uncomment the MsgBox itmAttach I get a blank message box, so it's
not pulling that variable right. However, even if I hard code the file
it's not working for me.

A little background info on this. I created one macro which does the
following:

1. Programatically calls the Edit Edit Message command.
2. Then opens this sticky.doc which is located on the desktop.

Then this second button will need to do the steps I outline above. Can
anyone see the problem with my code? Thanks.


I wish, that might be easier. No the word document is stored
statically in one spot. The problem is that the attachment does not
appear in the email. The saving of the word document works fine, once
you add the reference to the Microsoft Word 11 or 12 library,
depending on the version. I'm thinking the problem might be that this
is not an email waiting to be sent. This is an email already received,
that's been opened, set into what I call "Edit Mode"(clicking Edit
Edit Message).

But then I took out the code that deals with Word and tried to attach
the file to a new email, and it still doesn't work. No error message,
just doesn't work for me. Thanks.


  #7  
Old June 24th 08, 11:41 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Attach file to Current Email

I meant "How many *open* messages do you have when the code is executed?"

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Dmitry Streblechenko" wrote in message
...
How many messages do you have when te hcode is executed?
Does it work if you explicitly create a new message?

Set objItem = objOutlook.CreateItem(0)
Set objAttachments = objItem.Attachments
objAttachments.Add "C:\Documents and
Settings\dhenshaw\desktop\sticky.doc"
objItem.Display


--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Ayth" wrote in message
...
On Jun 24, 2:37 pm, "Dmitry Streblechenko" wrote:
So the problem is that you cannot figure out where the Woird document is
stored, right?
You might want to ask that question in one of the Word newsgroups, but I
can
imagine that Word document exposes the file name property explicitly.

--
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-"Ayth" wrote in message

...
On Jun 24, 1:39 pm, "Dmitry Streblechenko" wrote:



Application.ActiveInspector.CurrentItem.Attachment s.Add "c:\my
document.doc"


--
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-"Ayth" wrote in message


...


Hello,


Can someone point me in the right direction? Or some sample code that
would do the following:


1. Save the current active document in Word.
2. Attach it to the current email
3. Save the email since it will be in "Edit Mode".


I can do number one without a problem, but it's the second portion
that's giving me problems. I know I'll have to use GetInspector to
use
the current item, but I'm having troubles. Thanks.


Cheers,


Darrin


That was what I was starting to get at but it's still not working for
me. Here is my code so far:

Sub Save_Attach()
Dim objMSWord As Word.Application
Dim itmWord As Word.Document
Dim objOutlook As Outlook.Application
Dim objInspector As Outlook.Inspector
Dim objItem As Object 'Allow any Outlook item type.
Dim itmAttach
Dim objAttachments As Outlook.Attachments

itmAttach = Environ("userprofile") & "\Desktop\Sticky.doc"
' Convert it to a string.
itmAttach = StrConv(itmOpen, vbProperCase)
' The ActiveInspector is the currently open item.
'MsgBox itmAttach
Set objInspector = objOutlook.ActiveInspector
Set objItem = objInspector.CurrentItem
Set objAttachments = objItem.Attachments
Set objMSWord = Word.Application
Set itmWord = objMSWord.ActiveDocument
itmWord.Save
objAttachments.Add "C:\Documents and Settings\dhenshaw\desktop
\sticky.doc"
End Sub

As you can see I'm pulling the environmental variable userprofile,
tacking on the "\Desktop\sticky.doc" to it. That works fine in another
macro I created to open that document.

If I uncomment the MsgBox itmAttach I get a blank message box, so it's
not pulling that variable right. However, even if I hard code the file
it's not working for me.

A little background info on this. I created one macro which does the
following:

1. Programatically calls the Edit Edit Message command.
2. Then opens this sticky.doc which is located on the desktop.

Then this second button will need to do the steps I outline above. Can
anyone see the problem with my code? Thanks.


I wish, that might be easier. No the word document is stored
statically in one spot. The problem is that the attachment does not
appear in the email. The saving of the word document works fine, once
you add the reference to the Microsoft Word 11 or 12 library,
depending on the version. I'm thinking the problem might be that this
is not an email waiting to be sent. This is an email already received,
that's been opened, set into what I call "Edit Mode"(clicking Edit
Edit Message).

But then I took out the code that deals with Word and tried to attach
the file to a new email, and it still doesn't work. No error message,
just doesn't work for me. Thanks.



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Button to move current email to same folder in PST file? planetthoughtful Outlook and VBA 0 May 2nd 07 02:55 AM
Attach file vs insert file TOP Outlook - General Queries 2 March 17th 07 01:29 PM
How do I attach a file as a shortcut? Christa Outlook - General Queries 2 September 15th 06 10:29 AM
how can I attach pix file to email on yahoo? heckuvastud Outlook - General Queries 0 March 26th 06 11:51 PM
Send mass email and attach file! barryderay Outlook and VBA 1 March 15th 06 07:01 PM


All times are GMT +1. The time now is 12:50 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.