Group:  Microsoft Outlook ยป microsoft.public.outlook.program_vba
Thread: Macro not working under Vista

Macro not working under Vista
twentw 12/30/2008 3:30:01 AM
I've got a macro that saves emails as a text file. This was cobbled together
from various online sources with some small modifications since I know very
little about Visual Basic. In any event, I've been using this macro for
years with Outlook 2003 and 2007 under XP. I'm now trying to use it with
Outlook 2007 under Vista, and it doesn't work. All that happens is the
warning about accessing email information, I click "allow" and then nothing.
I'm thinking there's some security thing in Vista that's preventing
execution. I have macro security in Outlook turned off. UAC in Vista is
also turned off. Any ideas? I can post the code if that could be an issue.

Re: Macro not working under Vista
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 12/30/2008 1:57:00 PM
Show the macro code.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"twentw" <twentw[ at ]discussions.microsoft.com> wrote in message
news:EB12997C-B1BD-4EF1-9BF2-5A54E4439D2F[ at ]microsoft.com...
[Quoted Text]
> I've got a macro that saves emails as a text file. This was cobbled
> together
> from various online sources with some small modifications since I know
> very
> little about Visual Basic. In any event, I've been using this macro for
> years with Outlook 2003 and 2007 under XP. I'm now trying to use it with
> Outlook 2007 under Vista, and it doesn't work. All that happens is the
> warning about accessing email information, I click "allow" and then
> nothing.
> I'm thinking there's some security thing in Vista that's preventing
> execution. I have macro security in Outlook turned off. UAC in Vista is
> also turned off. Any ideas? I can post the code if that could be an
> issue.
>

Re: Macro not working under Vista
twentw 12/31/2008 3:31:00 AM
OK - Here it is:

'----------START OF CODE -----------
Public Declare Function apiGetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long




Public Sub GetMails()


' extract the selected mail into .doc format

Printfile

' extract attachments from selected mail


ExitSub:

Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing

End Sub



Public Function Printfile()

Dim objMessage As Object
Dim oiMail As MailItem
Dim strSubj As String
Dim objSelection As Outlook.Selection
Dim objOL As Outlook.Application
Dim i As Long
Dim fol As String

On Error Resume Next



' Instantiate an Outlook Application object.
Set objOL = CreateObject("Outlook.Application")
' Get the collection of selected objects.
Set objSelection = objOL.ActiveExplorer.Selection
For Each objMessage In objSelection
Set oiMail = objMessage

oiMailsubj = oiMail.Subject 'Subject
oimailsubj1 = RemoveChars(oiMail.Subject)
oiMailbody = oiMail.Body 'Body
oiMailsname = oiMail.SenderName 'Sender Name
oiMailsize = oiMail.Size 'Mail Size
oiMailattach = oiMail.Attachments.Count 'Attachment count
If IsEmpty(oiMailattach) Or oiMailattach = 0 Then
oiMailattach = "no"
Else
oiMailattach = "yes"

For iCtr = 1 To oiMail.Attachments.Count
oiMailattachname = oiMail.Attachments.Item(iCtr).FileName
Next iCtr
End If

oiMailrtime = oiMail.ReceivedTime 'Received Time
oiMailrtime1 = ReplaceSlash((oiMailrtime))
oiMailrtime2 = ReplaceColon((oiMailrtime1))

'This generates a new text file each time it is run. To keep adding to the
Text file

Set objDialog = CreateObject("SAFRCFileDlg.FileSave")

If oiMailsname = "John Doe" Then

objDialog.FileName = "C:\Sync\Email to " & oiMail.To & " " &
oiMailrtime2 & ".txt"
objDialog.FileType = "Text File"

intreturn = objDialog.OpenFileSaveDlg

If intreturn Then

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.CreateTextFile(objDialog.FileName)

objFile.WriteLine "Sender: John Doe"
objFile.WriteLine "To: " & oiMail.To
objFile.WriteLine "Subject: " & oiMailsubj
objFile.WriteLine "Cc: " & oiMail.CC
objFile.WriteLine "Size: " & oiMailsize
objFile.WriteLine "Attachment: " & oiMailattach
objFile.WriteLine "Attachment file name: " & oiMailattachname
objFile.WriteLine "Sent on: " & oiMailrtime
objFile.WriteLine "Body: " & vbCrLf & vbCrLf & oiMailbody

objFile.Close

Else

WScript.Quit

End If

Else

objDialog.FileName = "C:\Sync\Email from " & oiMailsname & " " &
oiMailrtime2 & ".txt"
objDialog.FileType = "Text File"

intreturn = objDialog.OpenFileSaveDlg


If intreturn Then

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.CreateTextFile(objDialog.FileName)

objFile.WriteLine "Sender: " & oiMailsname
objFile.WriteLine "To: " & oiMail.To
objFile.WriteLine "Subject: " & oiMailsubj
objFile.WriteLine "Cc: " & oiMail.CC
objFile.WriteLine "Size: " & oiMailsize
objFile.WriteLine "Attachment: " & oiMailattach
objFile.WriteLine "Attachment file name: " & oiMailattachname
objFile.WriteLine "Received on: " & oiMailrtime
objFile.WriteLine "Body: " & vbCrLf & vbCrLf & oiMailbody

objFile.Close

Else

WScript.Quit
End If
End If


Next


End Function



Function RemoveChars(Text As String) As String
Dim x As Byte
Const Unwanted = "\/?*.:<>" 'add other characters if needed
RemoveChars = Text
For x = 1 To Len(Unwanted)
RemoveChars = Replace(RemoveChars, Mid(Unwanted, x, 1), "")
Next
End Function

Function ReplaceSlash(Text As String) As String
Dim x As Byte
Const Unwanted = "/" 'add other characters if needed
ReplaceSlash = Text
For x = 1 To Len(Unwanted)
ReplaceSlash = Replace(ReplaceSlash, Mid(Unwanted, x, 1), "-")
Next
End Function
Function ReplaceColon(Text As String) As String
Dim x As Byte
Const Unwanted = ":" 'add other characters if needed
ReplaceColon = Text
For x = 1 To Len(Unwanted)
ReplaceColon = Replace(ReplaceColon, Mid(Unwanted, x, 1), ".")
Next
End Function
' ------------END OF CODE -------------






"Ken Slovak - [MVP - Outlook]" wrote:

[Quoted Text]
> Show the macro code.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "twentw" <twentw[ at ]discussions.microsoft.com> wrote in message
> news:EB12997C-B1BD-4EF1-9BF2-5A54E4439D2F[ at ]microsoft.com...
> > I've got a macro that saves emails as a text file. This was cobbled
> > together
> > from various online sources with some small modifications since I know
> > very
> > little about Visual Basic. In any event, I've been using this macro for
> > years with Outlook 2003 and 2007 under XP. I'm now trying to use it with
> > Outlook 2007 under Vista, and it doesn't work. All that happens is the
> > warning about accessing email information, I click "allow" and then
> > nothing.
> > I'm thinking there's some security thing in Vista that's preventing
> > execution. I have macro security in Outlook turned off. UAC in Vista is
> > also turned off. Any ideas? I can post the code if that could be an
> > issue.
> >
>
>
Re: Macro not working under Vista
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 12/31/2008 2:07:46 PM
Do you have an active and up to date AV program running on that Vista
machine?

Do you know exactly which line causes the warning message? Try stepping the
code to see that.

Offhand I'd suggest changing your declaration of the Outlook.Application
object from this:

Set objOL = CreateObject("Outlook.Application")

to this:

Set objOL = Application

See if that makes a difference when you use the trusted Application object
instead of an untrusted one.


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"twentw" <twentw[ at ]discussions.microsoft.com> wrote in message
news:6512FC9A-AF8D-4C0C-8E6A-CCFC36CD9050[ at ]microsoft.com...
[Quoted Text]
> OK - Here it is:
>
> '----------START OF CODE -----------
> Public Declare Function apiGetUserName Lib "advapi32.dll" Alias
> "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
>
>
>
>
> Public Sub GetMails()
>
>
> ' extract the selected mail into .doc format
>
> Printfile
>
> ' extract attachments from selected mail
>
>
> ExitSub:
>
> Set objAttachments = Nothing
> Set objMsg = Nothing
> Set objSelection = Nothing
> Set objOL = Nothing
>
> End Sub
>
>
>
> Public Function Printfile()
>
> Dim objMessage As Object
> Dim oiMail As MailItem
> Dim strSubj As String
> Dim objSelection As Outlook.Selection
> Dim objOL As Outlook.Application
> Dim i As Long
> Dim fol As String
>
> On Error Resume Next
>
>
>
> ' Instantiate an Outlook Application object.
> Set objOL = CreateObject("Outlook.Application")
> ' Get the collection of selected objects.
> Set objSelection = objOL.ActiveExplorer.Selection
> For Each objMessage In objSelection
> Set oiMail = objMessage
>
> oiMailsubj = oiMail.Subject 'Subject
> oimailsubj1 = RemoveChars(oiMail.Subject)
> oiMailbody = oiMail.Body 'Body
> oiMailsname = oiMail.SenderName 'Sender Name
> oiMailsize = oiMail.Size 'Mail Size
> oiMailattach = oiMail.Attachments.Count 'Attachment count
> If IsEmpty(oiMailattach) Or oiMailattach = 0 Then
> oiMailattach = "no"
> Else
> oiMailattach = "yes"
>
> For iCtr = 1 To oiMail.Attachments.Count
> oiMailattachname = oiMail.Attachments.Item(iCtr).FileName
> Next iCtr
> End If
>
> oiMailrtime = oiMail.ReceivedTime 'Received Time
> oiMailrtime1 = ReplaceSlash((oiMailrtime))
> oiMailrtime2 = ReplaceColon((oiMailrtime1))
>
> 'This generates a new text file each time it is run. To keep adding to the
> Text file
>
> Set objDialog = CreateObject("SAFRCFileDlg.FileSave")
>
> If oiMailsname = "John Doe" Then
>
> objDialog.FileName = "C:\Sync\Email to " & oiMail.To & " " &
> oiMailrtime2 & ".txt"
> objDialog.FileType = "Text File"
>
> intreturn = objDialog.OpenFileSaveDlg
>
> If intreturn Then
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
>
> Set objFile = objFSO.CreateTextFile(objDialog.FileName)
>
> objFile.WriteLine "Sender: John Doe"
> objFile.WriteLine "To: " & oiMail.To
> objFile.WriteLine "Subject: " & oiMailsubj
> objFile.WriteLine "Cc: " & oiMail.CC
> objFile.WriteLine "Size: " & oiMailsize
> objFile.WriteLine "Attachment: " & oiMailattach
> objFile.WriteLine "Attachment file name: " & oiMailattachname
> objFile.WriteLine "Sent on: " & oiMailrtime
> objFile.WriteLine "Body: " & vbCrLf & vbCrLf & oiMailbody
>
> objFile.Close
>
> Else
>
> WScript.Quit
>
> End If
>
> Else
>
> objDialog.FileName = "C:\Sync\Email from " & oiMailsname & " " &
> oiMailrtime2 & ".txt"
> objDialog.FileType = "Text File"
>
> intreturn = objDialog.OpenFileSaveDlg
>
>
> If intreturn Then
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
>
> Set objFile = objFSO.CreateTextFile(objDialog.FileName)
>
> objFile.WriteLine "Sender: " & oiMailsname
> objFile.WriteLine "To: " & oiMail.To
> objFile.WriteLine "Subject: " & oiMailsubj
> objFile.WriteLine "Cc: " & oiMail.CC
> objFile.WriteLine "Size: " & oiMailsize
> objFile.WriteLine "Attachment: " & oiMailattach
> objFile.WriteLine "Attachment file name: " & oiMailattachname
> objFile.WriteLine "Received on: " & oiMailrtime
> objFile.WriteLine "Body: " & vbCrLf & vbCrLf & oiMailbody
>
> objFile.Close
>
> Else
>
> WScript.Quit
> End If
> End If
>
>
> Next
>
>
> End Function
>
>
>
> Function RemoveChars(Text As String) As String
> Dim x As Byte
> Const Unwanted = "\/?*.:<>" 'add other characters if needed
> RemoveChars = Text
> For x = 1 To Len(Unwanted)
> RemoveChars = Replace(RemoveChars, Mid(Unwanted, x, 1), "")
> Next
> End Function
>
> Function ReplaceSlash(Text As String) As String
> Dim x As Byte
> Const Unwanted = "/" 'add other characters if needed
> ReplaceSlash = Text
> For x = 1 To Len(Unwanted)
> ReplaceSlash = Replace(ReplaceSlash, Mid(Unwanted, x, 1), "-")
> Next
> End Function
> Function ReplaceColon(Text As String) As String
> Dim x As Byte
> Const Unwanted = ":" 'add other characters if needed
> ReplaceColon = Text
> For x = 1 To Len(Unwanted)
> ReplaceColon = Replace(ReplaceColon, Mid(Unwanted, x, 1), ".")
> Next
> End Function
> ' ------------END OF CODE -------------
>
>
>
>
>
>
> "Ken Slovak - [MVP - Outlook]" wrote:
>
>> Show the macro code.
>>
>> --
>> Ken Slovak
>> [MVP - Outlook]
>> http://www.slovaktech.com
>> Author: Professional Programming Outlook 2007.
>> Reminder Manager, Extended Reminders, Attachment Options.
>> http://www.slovaktech.com/products.htm
>>
>>
>> "twentw" <twentw[ at ]discussions.microsoft.com> wrote in message
>> news:EB12997C-B1BD-4EF1-9BF2-5A54E4439D2F[ at ]microsoft.com...
>> > I've got a macro that saves emails as a text file. This was cobbled
>> > together
>> > from various online sources with some small modifications since I know
>> > very
>> > little about Visual Basic. In any event, I've been using this macro
>> > for
>> > years with Outlook 2003 and 2007 under XP. I'm now trying to use it
>> > with
>> > Outlook 2007 under Vista, and it doesn't work. All that happens is the
>> > warning about accessing email information, I click "allow" and then
>> > nothing.
>> > I'm thinking there's some security thing in Vista that's preventing
>> > execution. I have macro security in Outlook turned off. UAC in Vista
>> > is
>> > also turned off. Any ideas? I can post the code if that could be an
>> > issue.
>> >
>>
>>

Re: Macro not working under Vista
twentw 1/1/2009 12:06:01 AM
I have no antivirus running on this machine.

I'm trying to step through the code, but maybe I'm doing something wrong.
The only line that gets highlighted is Public Sub GetMails(), then it's done.
This is the same on the machine the code is working on. Is there a way to
get it to step through the code line by line?

I tried changing it to Set objOL = Application, but the only difference is
that the access warning window doesn't pop up.

"Ken Slovak - [MVP - Outlook]" wrote:

[Quoted Text]
> Do you have an active and up to date AV program running on that Vista
> machine?
>
> Do you know exactly which line causes the warning message? Try stepping the
> code to see that.
>
> Offhand I'd suggest changing your declaration of the Outlook.Application
> object from this:
>
> Set objOL = CreateObject("Outlook.Application")
>
> to this:
>
> Set objOL = Application
>
> See if that makes a difference when you use the trusted Application object
> instead of an untrusted one.
>
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "twentw" <twentw[ at ]discussions.microsoft.com> wrote in message
> news:6512FC9A-AF8D-4C0C-8E6A-CCFC36CD9050[ at ]microsoft.com...
> > OK - Here it is:
> >
> > '----------START OF CODE -----------
> > Public Declare Function apiGetUserName Lib "advapi32.dll" Alias
> > "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
> >
> >
> >
> >
> > Public Sub GetMails()
> >
> >
> > ' extract the selected mail into .doc format
> >
> > Printfile
> >
> > ' extract attachments from selected mail
> >
> >
> > ExitSub:
> >
> > Set objAttachments = Nothing
> > Set objMsg = Nothing
> > Set objSelection = Nothing
> > Set objOL = Nothing
> >
> > End Sub
> >
> >
> >
> > Public Function Printfile()
> >
> > Dim objMessage As Object
> > Dim oiMail As MailItem
> > Dim strSubj As String
> > Dim objSelection As Outlook.Selection
> > Dim objOL As Outlook.Application
> > Dim i As Long
> > Dim fol As String
> >
> > On Error Resume Next
> >
> >
> >
> > ' Instantiate an Outlook Application object.
> > Set objOL = CreateObject("Outlook.Application")
> > ' Get the collection of selected objects.
> > Set objSelection = objOL.ActiveExplorer.Selection
> > For Each objMessage In objSelection
> > Set oiMail = objMessage
> >
> > oiMailsubj = oiMail.Subject 'Subject
> > oimailsubj1 = RemoveChars(oiMail.Subject)
> > oiMailbody = oiMail.Body 'Body
> > oiMailsname = oiMail.SenderName 'Sender Name
> > oiMailsize = oiMail.Size 'Mail Size
> > oiMailattach = oiMail.Attachments.Count 'Attachment count
> > If IsEmpty(oiMailattach) Or oiMailattach = 0 Then
> > oiMailattach = "no"
> > Else
> > oiMailattach = "yes"
> >
> > For iCtr = 1 To oiMail.Attachments.Count
> > oiMailattachname = oiMail.Attachments.Item(iCtr).FileName
> > Next iCtr
> > End If
> >
> > oiMailrtime = oiMail.ReceivedTime 'Received Time
> > oiMailrtime1 = ReplaceSlash((oiMailrtime))
> > oiMailrtime2 = ReplaceColon((oiMailrtime1))
> >
> > 'This generates a new text file each time it is run. To keep adding to the
> > Text file
> >
> > Set objDialog = CreateObject("SAFRCFileDlg.FileSave")
> >
> > If oiMailsname = "John Doe" Then
> >
> > objDialog.FileName = "C:\Sync\Email to " & oiMail.To & " " &
> > oiMailrtime2 & ".txt"
> > objDialog.FileType = "Text File"
> >
> > intreturn = objDialog.OpenFileSaveDlg
> >
> > If intreturn Then
> >
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> >
> > Set objFile = objFSO.CreateTextFile(objDialog.FileName)
> >
> > objFile.WriteLine "Sender: John Doe"
> > objFile.WriteLine "To: " & oiMail.To
> > objFile.WriteLine "Subject: " & oiMailsubj
> > objFile.WriteLine "Cc: " & oiMail.CC
> > objFile.WriteLine "Size: " & oiMailsize
> > objFile.WriteLine "Attachment: " & oiMailattach
> > objFile.WriteLine "Attachment file name: " & oiMailattachname
> > objFile.WriteLine "Sent on: " & oiMailrtime
> > objFile.WriteLine "Body: " & vbCrLf & vbCrLf & oiMailbody
> >
> > objFile.Close
> >
> > Else
> >
> > WScript.Quit
> >
> > End If
> >
> > Else
> >
> > objDialog.FileName = "C:\Sync\Email from " & oiMailsname & " " &
> > oiMailrtime2 & ".txt"
> > objDialog.FileType = "Text File"
> >
> > intreturn = objDialog.OpenFileSaveDlg
> >
> >
> > If intreturn Then
> >
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> >
> > Set objFile = objFSO.CreateTextFile(objDialog.FileName)
> >
> > objFile.WriteLine "Sender: " & oiMailsname
> > objFile.WriteLine "To: " & oiMail.To
> > objFile.WriteLine "Subject: " & oiMailsubj
> > objFile.WriteLine "Cc: " & oiMail.CC
> > objFile.WriteLine "Size: " & oiMailsize
> > objFile.WriteLine "Attachment: " & oiMailattach
> > objFile.WriteLine "Attachment file name: " & oiMailattachname
> > objFile.WriteLine "Received on: " & oiMailrtime
> > objFile.WriteLine "Body: " & vbCrLf & vbCrLf & oiMailbody
> >
> > objFile.Close
> >
> > Else
> >
> > WScript.Quit
> > End If
> > End If
> >
> >
> > Next
> >
> >
> > End Function
> >
> >
> >
> > Function RemoveChars(Text As String) As String
> > Dim x As Byte
> > Const Unwanted = "\/?*.:<>" 'add other characters if needed
> > RemoveChars = Text
> > For x = 1 To Len(Unwanted)
> > RemoveChars = Replace(RemoveChars, Mid(Unwanted, x, 1), "")
> > Next
> > End Function
> >
> > Function ReplaceSlash(Text As String) As String
> > Dim x As Byte
> > Const Unwanted = "/" 'add other characters if needed
> > ReplaceSlash = Text
> > For x = 1 To Len(Unwanted)
> > ReplaceSlash = Replace(ReplaceSlash, Mid(Unwanted, x, 1), "-")
> > Next
> > End Function
> > Function ReplaceColon(Text As String) As String
> > Dim x As Byte
> > Const Unwanted = ":" 'add other characters if needed
> > ReplaceColon = Text
> > For x = 1 To Len(Unwanted)
> > ReplaceColon = Replace(ReplaceColon, Mid(Unwanted, x, 1), ".")
> > Next
> > End Function
> > ' ------------END OF CODE -------------
> >
> >
> >
> >
> >
> >
> > "Ken Slovak - [MVP - Outlook]" wrote:
> >
> >> Show the macro code.
> >>
> >> --
> >> Ken Slovak
> >> [MVP - Outlook]
> >> http://www.slovaktech.com
> >> Author: Professional Programming Outlook 2007.
> >> Reminder Manager, Extended Reminders, Attachment Options.
> >> http://www.slovaktech.com/products.htm
> >>
> >>
> >> "twentw" <twentw[ at ]discussions.microsoft.com> wrote in message
> >> news:EB12997C-B1BD-4EF1-9BF2-5A54E4439D2F[ at ]microsoft.com...
> >> > I've got a macro that saves emails as a text file. This was cobbled
> >> > together
> >> > from various online sources with some small modifications since I know
> >> > very
> >> > little about Visual Basic. In any event, I've been using this macro
> >> > for
> >> > years with Outlook 2003 and 2007 under XP. I'm now trying to use it
> >> > with
> >> > Outlook 2007 under Vista, and it doesn't work. All that happens is the
> >> > warning about accessing email information, I click "allow" and then
> >> > nothing.
> >> > I'm thinking there's some security thing in Vista that's preventing
> >> > execution. I have macro security in Outlook turned off. UAC in Vista
> >> > is
> >> > also turned off. Any ideas? I can post the code if that could be an
> >> > issue.
> >> >
> >>
> >>
>
>

Home | Search | Terms | Imprint
Newsgroups Reader