Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro - Sending E-mail - User-defined type not defined

Status
Not open for further replies.

Enkrypted

Technical User
Sep 18, 2002
663
US
I'm getting a "User-defined type not defined" error message when trying to run a macro. It points to the following code:

Code:
Dim OutApp As Outlook.Application

Looking into it, I have seen people mention to make sure the reference to the Microsoft Outlook Object Library. I checked and it is selected to reference to that. Any other ideas what it could be?

Enkrypted
A+
 

Hi,

In the VB Editor...

Tools > References

and CHECK off Microsoft Outlook Object Library.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I actually fixed it about 10 minutes ago, but ran into another issue. I'm now getting an "Object Required" message. Here is the code to the project for reference:

Code:
Sub SendEmail()

  'MsgBox "Welcome To Save PDF Module"
  Dim Filename As String
  Application.DisplayAlerts = False

' Save file name and path into a variable
   template_file = ActiveWorkbook.FullName
 
    Filename = ActiveCell.Value
' Default directory would be c:\temp.  Users however will have the ability to change where to save the file if need be.
' Notice that i'm only allowing the save as option to be of .txt format.
' I'm also attaching the current date to the file name.
   filesavename = Application.GetSaveAsFilename( _
    InitialFileName:="C:\" & Sheet7.Range("d17") & "-" & Sheet3.Range("B9") & ".pdf", _
    fileFilter:="PDF Files (*.pdf), *.pdf")
   
    If filesavename = False Then
        Exit Sub
    End If
   
    FilePath = filesavename
    
' Save file as .txt TAB delimited
     
    file_name_saved = ActiveWorkbook.FullName
    'MsgBox "Your Acct Rec upload file has been successfully created at: " & vbCr & vbCr & file_name_saved
   
   
' Go back to excel format after TAB delimited file has been created and saved
      ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=filesavename, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False

     Application.DisplayAlerts = True

  'MsgBox "Welcome to Email Sending Module"
  
  Dim OutApp As Outlook.Application
  Dim OutMail As Outlook.MailItem
  'Dim strname As String
  
  
  Set OutApp = New Outlook.Application
  Set OutMail = OutApp.CreateItem(0)
  'strname = ThisWorkbook.Sheets("Sheet1").Range("A1:A20").Value
  
  'MsgBox (ActiveCell.Value)
  'MsgBox (FilePath)
  If FilePath = "" Then
   MsgBox ("No Pdf exists to attach to the email. First save pdf and then send Email")
      Exit Sub
   End If
   
  With OutMail
  
   .To = Sheet8.Range("AE11")
   .Subject = "Test Message " & Sheet8.Range("AE5")
   .Body = "Test message."
   '.Attachments.Add ActiveWorkbook.FullName
   .Attachments.Add (FilePath)
   .Display
   
   End With
End Sub

I'm not sure where to begin to figure the problem as it gives no information as to what part could be failing.

Enkrypted
A+
 
If you step through the script, or hit debug, what line is highlighted?
 
It doesn't highlight any area. Just for a visual, it will prompt with a Save As dialog box and then once the OK button is clicked, is when the Object Required error appears.

Enkrypted
A+
 
I found the issue and resolved it. Thanks for help Skip

Enkrypted
A+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top