Hi There,
I need Some help with a problem in Excel.
I have a workbook in Excel wich need to be send by mail.
With a button in the workbook , the workbook has to be saved
as "anyName.xls" and then attached in outlook.
Now the SaveAs part works only when the name stays the same
as the original workbook-name. When I alter the name of the workbook, The attachment can't be made. An error pops up with 'Can't find file'.
What Am I doing wrong?
Here's the code:
Private Sub okbtn_Click()
On Error GoTo Err_okbtn_Click
Start:
Dim sFileName As String
Dim objOL As New Outlook.Application
Dim objMail As MailItem
Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
sFileName = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel-Werkmap(*.xls), *.xls"
If sFileName = "False" Then
ActiveWorkbook.SaveAs Filename:=sFileName
Else
DoCmd.CancelEvent
End If
Mail:
With objMail
.To = Form1.sReciptxt.Text
.CC = "Hans Zwennes"
.Subject = "Probleemhoek Formulier" & " " & Date
.Body = "Dit Is een Test"
.Display
.Attachments.Add sFileName
End With
Exit_okbtn_Click:
Set objMail = Nothing
Set objOL = Nothing
Unload Form1
Exit Sub
Err_okbtn_Click:
MsgBox Err.Description
Resume Exit_okbtn_Click
End Sub
I need Some help with a problem in Excel.
I have a workbook in Excel wich need to be send by mail.
With a button in the workbook , the workbook has to be saved
as "anyName.xls" and then attached in outlook.
Now the SaveAs part works only when the name stays the same
as the original workbook-name. When I alter the name of the workbook, The attachment can't be made. An error pops up with 'Can't find file'.
What Am I doing wrong?
Here's the code:
Private Sub okbtn_Click()
On Error GoTo Err_okbtn_Click
Start:
Dim sFileName As String
Dim objOL As New Outlook.Application
Dim objMail As MailItem
Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
sFileName = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel-Werkmap(*.xls), *.xls"
If sFileName = "False" Then
ActiveWorkbook.SaveAs Filename:=sFileName
Else
DoCmd.CancelEvent
End If
Mail:
With objMail
.To = Form1.sReciptxt.Text
.CC = "Hans Zwennes"
.Subject = "Probleemhoek Formulier" & " " & Date
.Body = "Dit Is een Test"
.Display
.Attachments.Add sFileName
End With
Exit_okbtn_Click:
Set objMail = Nothing
Set objOL = Nothing
Unload Form1
Exit Sub
Err_okbtn_Click:
MsgBox Err.Description
Resume Exit_okbtn_Click
End Sub