Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default file extension shows up twice on attachment

Hello-

I used the following code that I got from Ron De Bruins site to send a sheet in a workbook as an attachment in an email via Outlook. The problem I am having is that the attachment will have the file extension twice. It will look like Call Report.xls.xls. Can someone advise as to how to remove one of the extension names?

Thanks in advance

Sub Mail_ActiveSheet()
'Working in 2000-2010
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set Sourcewb = ActiveWorkbook

'Copy the sheet to a new workbook
ActiveSheet.Copy
Set Destwb = ActiveWorkbook

'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 2000-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007-2010, we exit the sub when your answer is
'NO in the security dialog that you only see when you copy
'an sheet from a xlsm file with macro's disabled.
If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With

' 'Change all cells in the worksheet to values if you want
' With Destwb.Sheets(1).UsedRange
' .Cells.Copy
' .Cells.PasteSpecial xlPasteValues
' .Cells(1).Select
' End With
' Application.CutCopyMode = False

'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = "Part of " & Sourcewb.Name & " " _
& Format(Now, "dd-mmm-yy h-mm-ss")

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.To = "
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add Destwb.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
On Error GoTo 0
.Close SaveChanges:=False
End With

'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr

Set OutMail = Nothing
Set OutApp = Nothing

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default file extension shows up twice on attachment

Try changing this:
With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum

to this:
With Destwb
.SaveAs TempFilePath & TempFileName, _
FileFormat:=FileFormatNum

i.e., do not add the extra FileExtStr to its name that already has the
extention.


On Jan 27, 1:45*pm, Sabosis wrote:
Hello-

I used the following code that I got from Ron De Bruins site to send a sheet in a workbook as an attachment in an email via Outlook. The problem I am having is that the attachment will have the file extension twice. It will look like Call Report.xls.xls. Can someone advise as to how to remove one of the extension names?

Thanks in advance

Sub Mail_ActiveSheet()
'Working in 2000-2010
* * Dim FileExtStr As String
* * Dim FileFormatNum As Long
* * Dim Sourcewb As Workbook
* * Dim Destwb As Workbook
* * Dim TempFilePath As String
* * Dim TempFileName As String
* * Dim OutApp As Object
* * Dim OutMail As Object

* * With Application
* * * * .ScreenUpdating = False
* * * * .EnableEvents = False
* * End With

* * Set Sourcewb = ActiveWorkbook

* * 'Copy the sheet to a new workbook
* * ActiveSheet.Copy
* * Set Destwb = ActiveWorkbook

* * 'Determine the Excel version and file extension/format
* * With Destwb
* * * * If Val(Application.Version) < 12 Then
* * * * * * 'You use Excel 2000-2003
* * * * * * FileExtStr = ".xls": FileFormatNum = -4143
* * * * Else
* * * * * * 'You use Excel 2007-2010, we exit the sub when your answer is
* * * * * * 'NO in the security dialog that you only see *when you copy
* * * * * * 'an sheet from a xlsm file with macro's disabled.
* * * * * * If Sourcewb.Name = .Name Then
* * * * * * * * With Application
* * * * * * * * * * .ScreenUpdating = True
* * * * * * * * * * .EnableEvents = True
* * * * * * * * End With
* * * * * * * * MsgBox "Your answer is NO in the security dialog"
* * * * * * * * Exit Sub
* * * * * * Else
* * * * * * * * Select Case Sourcewb.FileFormat
* * * * * * * * Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
* * * * * * * * Case 52:
* * * * * * * * * * If .HasVBProject Then
* * * * * * * * * * * * FileExtStr = ".xlsm": FileFormatNum = 52
* * * * * * * * * * Else
* * * * * * * * * * * * FileExtStr = ".xlsx": FileFormatNum = 51
* * * * * * * * * * End If
* * * * * * * * Case 56: FileExtStr = ".xls": FileFormatNum = 56
* * * * * * * * Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
* * * * * * * * End Select
* * * * * * End If
* * * * End If
* * End With

* * ' * *'Change all cells in the worksheet to values if you want
* * ' * *With Destwb.Sheets(1).UsedRange
* * ' * * * *.Cells.Copy
* * ' * * * *.Cells.PasteSpecial xlPasteValues
* * ' * * * *.Cells(1).Select
* * ' * *End With
* * ' * *Application.CutCopyMode = False

* * 'Save the new workbook/Mail it/Delete it
* * TempFilePath = Environ$("temp") & "\"
* * TempFileName = "Part of " & Sourcewb.Name & " " _
* * * * * * * * *& Format(Now, "dd-mmm-yy h-mm-ss")

* * Set OutApp = CreateObject("Outlook.Application")
* * Set OutMail = OutApp.CreateItem(0)

* * With Destwb
* * * * .SaveAs TempFilePath & TempFileName & FileExtStr, _
* * * * * * * * FileFormat:=FileFormatNum
* * * * On Error Resume Next
* * * * With OutMail
* * * * * * .To = "
* * * * * * .CC = ""
* * * * * * .BCC = ""
* * * * * * .Subject = "This is the Subject line"
* * * * * * .Body = "Hi there"
* * * * * * .Attachments.Add Destwb.FullName
* * * * * * 'You can add other files also like this
* * * * * * '.Attachments.Add ("C:\test.txt")
* * * * * * .Send * 'or use .Display
* * * * End With
* * * * On Error GoTo 0
* * * * .Close SaveChanges:=False
* * End With

* * 'Delete the file you have send
* * Kill TempFilePath & TempFileName & FileExtStr

* * Set OutMail = Nothing
* * Set OutApp = Nothing

* * With Application
* * * * .ScreenUpdating = True
* * * * .EnableEvents = True
* * End With
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default file extension shows up twice on attachment

The FileFormat argument takes care of the extension.you need not
specify it separately.If you add .xls then it will treat as filename
and again add the extension as required by fileformat.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
filter file extension on remote pc for file open Ludo Excel Programming 1 October 8th 09 05:24 PM
Determine Excel file version with no file extension. tjlumpkin Excel Discussion (Misc queries) 2 July 23rd 09 06:59 AM
Retrieving Excel File extension based on XL File Format Enumeratio Sasikumar Kannappan Excel Programming 2 June 24th 09 03:59 PM
file format or file extension is not valid...error message Ballun Excel Discussion (Misc queries) 0 May 7th 09 09:06 PM
Additional file with no extension created during File Save As proc Peter Rooney Excel Discussion (Misc queries) 2 August 11th 05 02:48 PM


All times are GMT +1. The time now is 06:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"