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

Please help - VBA to save email to drive



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 2nd 07, 11:23 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 3
Default Please help - VBA to save email to drive

I've been using the macro below (I got this from the Outlook VBA help
file - I'm not a heavy duty coder) to save selected email to a folder
on a hard drive. Users will be saving hundreds and hundreds of emails
in this manner, so I'm trying to automate it as much as possible.

I need to change two things:

1. Instead of naming the file using the "Subject:" string, open a box
so the user can name it.

2. In #1, the user will always enter a 6-digit number, e.g. "987021"
as the file name. A critical point is that over several months, the
user will save several files with the same name. When that happens,
the new file can NOT "replace the existing file by the same name."
There are two possible approaches to this:

One approach is to allow multiple files to be saved with the same
name. Maybe something like 987021-2, 987021-3, and so on, or whatever
could work. The user can NOT enter this "-2" or "-3" suffix, it needs
to be automatic. In any case, the user can only enter the 6-digit file
name.

A better approach would be where if the filename already exists, it
would catenate the new file to the existing one, instead of creating a
new one. I have utterly no idea how to do that. This approach would
actually be MUCH more preferable than the first one.

These two fixes would be enormously appreciated, and would save
several people a huge quantity of time and work.

Please reply only on the newsgroup.
Thanks,

Bill S.

Here's the current code:
******************************************
Sub saveemail()

Dim myItem As Outlook.Inspector
Dim objItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
strname = objItem.Subject
'Prompt the user for confirmation
Dim strPrompt As String
strPrompt = "Are you sure you want to save the item? If a file
with the same name already exists, it will be overwritten with this
copy of the file."
If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
objItem.SaveAs "S:\Funding Team\Communication\Region
1\Calendar Year 2007\" & strname & ".txt", olTXT
End If
Else
MsgBox "There is no current active inspector."
End If

End Sub

Ads
  #2  
Old July 3rd 07, 05:22 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Please help - VBA to save email to drive

You can use the InputBox function to prompt the user to input a string that
you can retrieve.

If you want to auto-generate a filename, you'd have to use a recursive loop
where you first check to see if the file exists (use the Dir statement); if
it doesn't, increment a numeric variable and continue the loop until Dir
returns an empty string - indicating the file doesn't exist.

Note that you can't automatically merge two files together unless they're
ASCII based (.txt, .html, etc.) - but then you'd still have to manually parse
and edit the text with code.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


" wrote:

I've been using the macro below (I got this from the Outlook VBA help
file - I'm not a heavy duty coder) to save selected email to a folder
on a hard drive. Users will be saving hundreds and hundreds of emails
in this manner, so I'm trying to automate it as much as possible.

I need to change two things:

1. Instead of naming the file using the "Subject:" string, open a box
so the user can name it.

2. In #1, the user will always enter a 6-digit number, e.g. "987021"
as the file name. A critical point is that over several months, the
user will save several files with the same name. When that happens,
the new file can NOT "replace the existing file by the same name."
There are two possible approaches to this:

One approach is to allow multiple files to be saved with the same
name. Maybe something like 987021-2, 987021-3, and so on, or whatever
could work. The user can NOT enter this "-2" or "-3" suffix, it needs
to be automatic. In any case, the user can only enter the 6-digit file
name.

A better approach would be where if the filename already exists, it
would catenate the new file to the existing one, instead of creating a
new one. I have utterly no idea how to do that. This approach would
actually be MUCH more preferable than the first one.

These two fixes would be enormously appreciated, and would save
several people a huge quantity of time and work.

Please reply only on the newsgroup.
Thanks,

Bill S.

Here's the current code:
******************************************
Sub saveemail()

Dim myItem As Outlook.Inspector
Dim objItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
strname = objItem.Subject
'Prompt the user for confirmation
Dim strPrompt As String
strPrompt = "Are you sure you want to save the item? If a file
with the same name already exists, it will be overwritten with this
copy of the file."
If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
objItem.SaveAs "S:\Funding Team\Communication\Region
1\Calendar Year 2007\" & strname & ".txt", olTXT
End If
Else
MsgBox "There is no current active inspector."
End If

End Sub


  #3  
Old July 3rd 07, 05:46 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 3
Default Please help - VBA to save email to drive

Thanks very much, Eric. If the files can't be merged together, that's
fine. I can't figure out how to do what you describe, though.

Ron


On Jul 3, 10:22 am, Eric Legault [MVP - Outlook]
wrote:
You can use the InputBox function to prompt the user to input a string that
you can retrieve.

If you want to auto-generate a filename, you'd have to use a recursive loop
where you first check to see if the file exists (use the Dir statement); if
it doesn't, increment a numeric variable and continue the loop until Dir
returns an empty string - indicating the file doesn't exist.

Note that you can't automatically merge two files together unless they're
ASCII based (.txt, .html, etc.) - but then you'd still have to manually parse
and edit the text with code.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:http://www.collaborativeinnovations.ca
Blog:http://blogs.officezealot.com/legault/

" wrote:
I've been using the macro below (I got this from the Outlook VBA help
file - I'm not a heavy duty coder) to save selected email to a folder
on a hard drive. Users will be saving hundreds and hundreds of emails
in this manner, so I'm trying to automate it as much as possible.


I need to change two things:


1. Instead of naming the file using the "Subject:" string, open a box
so the user can name it.


2. In #1, the user will always enter a 6-digit number, e.g. "987021"
as the file name. A critical point is that over several months, the
user will save several files with the same name. When that happens,
the new file can NOT "replace the existing file by the same name."
There are two possible approaches to this:


One approach is to allow multiple files to be saved with the same
name. Maybe something like 987021-2, 987021-3, and so on, or whatever
could work. The user can NOT enter this "-2" or "-3" suffix, it needs
to be automatic. In any case, the user can only enter the 6-digit file
name.


A better approach would be where if the filename already exists, it
would catenate the new file to the existing one, instead of creating a
new one. I have utterly no idea how to do that. This approach would
actually be MUCH more preferable than the first one.


These two fixes would be enormously appreciated, and would save
several people a huge quantity of time and work.


Please reply only on the newsgroup.
Thanks,


Bill S.


Here's the current code:
******************************************
Sub saveemail()


Dim myItem As Outlook.Inspector
Dim objItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
strname = objItem.Subject
'Prompt the user for confirmation
Dim strPrompt As String
strPrompt = "Are you sure you want to save the item? If a file
with the same name already exists, it will be overwritten with this
copy of the file."
If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
objItem.SaveAs "S:\Funding Team\Communication\Region
1\Calendar Year 2007\" & strname & ".txt", olTXT
End If
Else
MsgBox "There is no current active inspector."
End If


End Sub



  #4  
Old July 3rd 07, 06:30 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Please help - VBA to save email to drive

Here's a sample loop that illustrates looking for a file and appending a
number to the filename until a file with that name doesn't exist:

If Dir(strFolder & strFileName & strExtension, vbNormal) "" Then
Do
intX = intX + 1
strFileName = strFolder & strFileName & intX & strExtension
Loop Until Dir(strFileName, vbNormal) = ""
End If

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


" wrote:

Thanks very much, Eric. If the files can't be merged together, that's
fine. I can't figure out how to do what you describe, though.

Ron


On Jul 3, 10:22 am, Eric Legault [MVP - Outlook]
wrote:
You can use the InputBox function to prompt the user to input a string that
you can retrieve.

If you want to auto-generate a filename, you'd have to use a recursive loop
where you first check to see if the file exists (use the Dir statement); if
it doesn't, increment a numeric variable and continue the loop until Dir
returns an empty string - indicating the file doesn't exist.

Note that you can't automatically merge two files together unless they're
ASCII based (.txt, .html, etc.) - but then you'd still have to manually parse
and edit the text with code.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:http://www.collaborativeinnovations.ca
Blog:http://blogs.officezealot.com/legault/

" wrote:
I've been using the macro below (I got this from the Outlook VBA help
file - I'm not a heavy duty coder) to save selected email to a folder
on a hard drive. Users will be saving hundreds and hundreds of emails
in this manner, so I'm trying to automate it as much as possible.


I need to change two things:


1. Instead of naming the file using the "Subject:" string, open a box
so the user can name it.


2. In #1, the user will always enter a 6-digit number, e.g. "987021"
as the file name. A critical point is that over several months, the
user will save several files with the same name. When that happens,
the new file can NOT "replace the existing file by the same name."
There are two possible approaches to this:


One approach is to allow multiple files to be saved with the same
name. Maybe something like 987021-2, 987021-3, and so on, or whatever
could work. The user can NOT enter this "-2" or "-3" suffix, it needs
to be automatic. In any case, the user can only enter the 6-digit file
name.


A better approach would be where if the filename already exists, it
would catenate the new file to the existing one, instead of creating a
new one. I have utterly no idea how to do that. This approach would
actually be MUCH more preferable than the first one.


These two fixes would be enormously appreciated, and would save
several people a huge quantity of time and work.


Please reply only on the newsgroup.
Thanks,


Bill S.


Here's the current code:
******************************************
Sub saveemail()


Dim myItem As Outlook.Inspector
Dim objItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
strname = objItem.Subject
'Prompt the user for confirmation
Dim strPrompt As String
strPrompt = "Are you sure you want to save the item? If a file
with the same name already exists, it will be overwritten with this
copy of the file."
If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
objItem.SaveAs "S:\Funding Team\Communication\Region
1\Calendar Year 2007\" & strname & ".txt", olTXT
End If
Else
MsgBox "There is no current active inspector."
End If


End Sub




  #5  
Old July 4th 07, 03:22 AM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 3
Default Please help - VBA to save email to drive

Thanks, Eric. I'll try to work that into the code.

Can you possibly help me out with the other issue - letting the user
input the filename, instead of automatically using the Subject: line?
If I can't do that, I can't use the code below.

Thanks a heap,
Ron


On Jul 3, 11:30 am, Eric Legault [MVP - Outlook]
wrote:
Here's a sample loop that illustrates looking for a file and appending a
number to the filename until a file with that name doesn't exist:

If Dir(strFolder & strFileName & strExtension, vbNormal) "" Then
Do
intX = intX + 1
strFileName = strFolder & strFileName & intX & strExtension
Loop Until Dir(strFileName, vbNormal) = ""
End If

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:http://www.collaborativeinnovations.ca
Blog:http://blogs.officezealot.com/legault/

" wrote:
Thanks very much, Eric. If the files can't be merged together, that's
fine. I can't figure out how to do what you describe, though.


Ron


On Jul 3, 10:22 am, Eric Legault [MVP - Outlook]
wrote:
You can use the InputBox function to prompt the user to input a string that
you can retrieve.


If you want to auto-generate a filename, you'd have to use a recursive loop
where you first check to see if the file exists (use the Dir statement); if
it doesn't, increment a numeric variable and continue the loop until Dir
returns an empty string - indicating the file doesn't exist.


Note that you can't automatically merge two files together unless they're
ASCII based (.txt, .html, etc.) - but then you'd still have to manually parse
and edit the text with code.


--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:http://www.collaborativeinnovations.ca
Blog:http://blogs.officezealot.com/legault/


" wrote:
I've been using the macro below (I got this from the Outlook VBA help
file - I'm not a heavy duty coder) to save selected email to a folder
on a hard drive. Users will be saving hundreds and hundreds of emails
in this manner, so I'm trying to automate it as much as possible.


I need to change two things:


1. Instead of naming the file using the "Subject:" string, open a box
so the user can name it.


2. In #1, the user will always enter a 6-digit number, e.g. "987021"
as the file name. A critical point is that over several months, the
user will save several files with the same name. When that happens,
the new file can NOT "replace the existing file by the same name."
There are two possible approaches to this:


One approach is to allow multiple files to be saved with the same
name. Maybe something like 987021-2, 987021-3, and so on, or whatever
could work. The user can NOT enter this "-2" or "-3" suffix, it needs
to be automatic. In any case, the user can only enter the 6-digit file
name.


A better approach would be where if the filename already exists, it
would catenate the new file to the existing one, instead of creating a
new one. I have utterly no idea how to do that. This approach would
actually be MUCH more preferable than the first one.


These two fixes would be enormously appreciated, and would save
several people a huge quantity of time and work.


Please reply only on the newsgroup.
Thanks,


Bill S.


Here's the current code:
******************************************
Sub saveemail()


Dim myItem As Outlook.Inspector
Dim objItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
strname = objItem.Subject
'Prompt the user for confirmation
Dim strPrompt As String
strPrompt = "Are you sure you want to save the item? If a file
with the same name already exists, it will be overwritten with this
copy of the file."
If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
objItem.SaveAs "S:\Funding Team\Communication\Region
1\Calendar Year 2007\" & strname & ".txt", olTXT
End If
Else
MsgBox "There is no current active inspector."
End If


End Sub



  #6  
Old July 4th 07, 03:34 AM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Please help - VBA to save email to drive

Just use the InputBox function - that'll present a dialog that will allow the
user to type in the file name they want. The function returns a string. You
can always put your cursor on the function name and press F1 to see the help
reference for it.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


" wrote:

Thanks, Eric. I'll try to work that into the code.

Can you possibly help me out with the other issue - letting the user
input the filename, instead of automatically using the Subject: line?
If I can't do that, I can't use the code below.

Thanks a heap,
Ron


On Jul 3, 11:30 am, Eric Legault [MVP - Outlook]
wrote:
Here's a sample loop that illustrates looking for a file and appending a
number to the filename until a file with that name doesn't exist:

If Dir(strFolder & strFileName & strExtension, vbNormal) "" Then
Do
intX = intX + 1
strFileName = strFolder & strFileName & intX & strExtension
Loop Until Dir(strFileName, vbNormal) = ""
End If

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:http://www.collaborativeinnovations.ca
Blog:http://blogs.officezealot.com/legault/

" wrote:
Thanks very much, Eric. If the files can't be merged together, that's
fine. I can't figure out how to do what you describe, though.


Ron


On Jul 3, 10:22 am, Eric Legault [MVP - Outlook]
wrote:
You can use the InputBox function to prompt the user to input a string that
you can retrieve.


If you want to auto-generate a filename, you'd have to use a recursive loop
where you first check to see if the file exists (use the Dir statement); if
it doesn't, increment a numeric variable and continue the loop until Dir
returns an empty string - indicating the file doesn't exist.


Note that you can't automatically merge two files together unless they're
ASCII based (.txt, .html, etc.) - but then you'd still have to manually parse
and edit the text with code.


--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:http://www.collaborativeinnovations.ca
Blog:http://blogs.officezealot.com/legault/


" wrote:
I've been using the macro below (I got this from the Outlook VBA help
file - I'm not a heavy duty coder) to save selected email to a folder
on a hard drive. Users will be saving hundreds and hundreds of emails
in this manner, so I'm trying to automate it as much as possible.


I need to change two things:


1. Instead of naming the file using the "Subject:" string, open a box
so the user can name it.


2. In #1, the user will always enter a 6-digit number, e.g. "987021"
as the file name. A critical point is that over several months, the
user will save several files with the same name. When that happens,
the new file can NOT "replace the existing file by the same name."
There are two possible approaches to this:


One approach is to allow multiple files to be saved with the same
name. Maybe something like 987021-2, 987021-3, and so on, or whatever
could work. The user can NOT enter this "-2" or "-3" suffix, it needs
to be automatic. In any case, the user can only enter the 6-digit file
name.


A better approach would be where if the filename already exists, it
would catenate the new file to the existing one, instead of creating a
new one. I have utterly no idea how to do that. This approach would
actually be MUCH more preferable than the first one.


These two fixes would be enormously appreciated, and would save
several people a huge quantity of time and work.


Please reply only on the newsgroup.
Thanks,


Bill S.


Here's the current code:
******************************************
Sub saveemail()


Dim myItem As Outlook.Inspector
Dim objItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
strname = objItem.Subject
'Prompt the user for confirmation
Dim strPrompt As String
strPrompt = "Are you sure you want to save the item? If a file
with the same name already exists, it will be overwritten with this
copy of the file."
If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
objItem.SaveAs "S:\Funding Team\Communication\Region
1\Calendar Year 2007\" & strname & ".txt", olTXT
End If
Else
MsgBox "There is no current active inspector."
End If


End Sub




 




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
what files to save for hard drive format smokiibear Outlook - General Queries 2 April 23rd 07 04:30 PM
save attachment to a location in C drive folder Rayvi Outlook and VBA 1 April 18th 07 02:15 PM
how do I save my outlook to my flash drive Marianne Z Outlook - Calandaring 2 April 12th 07 06:55 PM
Save e-mail as documents to USB drive CJC Outlook - General Queries 3 January 23rd 07 09:31 PM
How can I save an Outlook calander to a flash drive? tkaddatz Outlook - Calandaring 3 February 7th 06 08:10 AM


All times are GMT +1. The time now is 08:04 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.