?
Solved

Assign Objectname to String Variable

Posted on 2003-03-06
5
Medium Priority
?
203 Views
Last Modified: 2012-06-21
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
Comment
Question by:Digriz60
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:navneet77
ID: 8084475
hey where are you assigning anything to myitem
when you do this Set myAttach = myitem.Attachments(1)
   myitem seems to have nothing
0
 
LVL 2

Accepted Solution

by:
navneet77 earned 150 total points
ID: 8084481
Even myattach seems to be not set anywhere.. is there other code in between
0
 

Author Comment

by:Digriz60
ID: 8084551
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
 
LVL 2

Expert Comment

by:navneet77
ID: 8084581
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
 

Author Comment

by:Digriz60
ID: 8084593
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question