• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

Assign Objectname to String Variable

I'm trying to change the name of an Outlook attachment and detach it to a particular directory, using Outlook VBA. Ive tried dimming ConName/1 as Variant, but it doesn't like to assign an object to a non-object variable..is there any way around this?
Here is a chunk of my code

Dim myitem As Outlook.MailItem
Dim myAttach As Outlook.Attachment
Dim ConName As String
Dim ConName1 As String

ConName = Left(myAttach.FileName, 14) & ".txt"
ConName1 = Left(myAttach.FileName, 6) & ".csv"
   
    Set myAttach = myitem.Attachments(1)
    myAttach.SaveAsFile "t:\" & myAttach.FileName
    myAttach.SaveAsFile "t:\" & ConName
    myAttach.SaveAsFile "j:\" & ConName1
 


0
Digriz60
Asked:
Digriz60
  • 3
  • 2
1 Solution
 
navneet77Commented:
hey where are you assigning anything to myitem
when you do this Set myAttach = myitem.Attachments(1)
   myitem seems to have nothing
0
 
navneet77Commented:
Even myattach seems to be not set anywhere.. is there other code in between
0
 
Digriz60Author Commented:
Sorry, I was trying to conserve space so I Reader's Digested my code...here's the full code:


Private Sub Application_NewMail()
Dim myfolder As Object
Dim i As Integer
Dim b As Integer
Dim myitem As Outlook.MailItem
Dim myAttach As Outlook.Attachment
Dim title As String
Dim ConName As Variant
Dim ConName1 As Variant

Dim OrdName As String
Dim OrdName1 As String
Dim myname As String
Dim MartName As String

Dim MineName As String
Dim Fred As Integer



Set myfolder = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set myitem = myfolder.Items(1)
title = myitem.Subject

If Right(title, 7) = "Confirm" Then

Set ConName = Left(myAttach.FileName, 14) & ".txt"
Set ConName1 = Left(myAttach.FileName, 6) & ".csv"
   
    Set myAttach = myitem.Attachments(1)
    myAttach.SaveAsFile "t:\" & myAttach.FileName
    myAttach.SaveAsFile "t:\" & ConName
    myAttach.SaveAsFile "j:\" & ConName1
    End If
0
 
navneet77Commented:
Set ConName = Left(myAttach.FileName, 14) & ".txt"
Set ConName1 = Left(myAttach.FileName, 6) & ".csv"

i dont thing you can do this with a string because
Left(myAttach.FileName, 14) & ".txt"
is just a string

what error does it give and where when you try

dim conName as string
conName = Left(myAttach.FileName, 14) & ".txt"
0
 
Digriz60Author Commented:
I figured it out..the line for Set myAttach=myitem.Attachments(1) came after I was assigning the ConName variable. You get the points for my stupidity.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now