Reference problem

jakeb3482

Board Regular
Joined
Mar 6, 2006
Messages
74
Ok so I am having a bit of problems with some references.

I have some scripts that used to run fine until I needed to use the Microsoft Outlook 11.0 Library for a different script that I made.

Now I get errors with the "Name" property in the old scripts. When i uncheck the Microsoft Outlook library box in Tools> References, the scripts work fine with no errors about the "Name" property.

How can I set up VBA to have all of the scripts working without checking and unchecking that box.

Thanks,
Jake
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,831
Office Version
  1. 365
Platform
  1. Windows
Jake

You could use late-binding which would eliminate the need for any references.

To give you more details about that it would be useful to see your code.
 

jakeb3482

Board Regular
Joined
Mar 6, 2006
Messages
74
Thanks Norie,

What is late-binding? and
What part of my code do you need to see? It is pretty long...

Thanks,
Jake
 

jakeb3482

Board Regular
Joined
Mar 6, 2006
Messages
74
Second thoughts, I will research late-binding so you dont have to explain it to me.

Thanks :)
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,831
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Jake

Late-binding is a method where you don't actually need to declare objects with their specific data type.

For example say your code is automating Word.

You might have declarations like this.
Code:
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Now for the code to work you would require a reference to the MS Word X.0 Object Library.

This is called early binding.

With late binding the declarations would be more like this.
Code:
Dim wdApp As Object
Dim wdDoc As Object
There are advantages and disadvantages to both methods, you'll find plenty of articles if you do search on the web.

As to your specific problem it would help to actually know the references involved and what you are actually doing.

Post the code that requires the references.
 

jakeb3482

Board Regular
Joined
Mar 6, 2006
Messages
74
Code:
    Dim OutApp As Outlook.Application
    Dim OutMail As Outlook.MailItem
    Dim RecipName As String
    Dim WordApp As Word.Application
    Dim OLbCreated As Boolean

the code i have automatically emails the output file from my script to whoever i choose.

thanks for your assistance. i will be looking forward to your reply.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,831
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

It might help to see some more of the code.:)
 

jakeb3482

Board Regular
Joined
Mar 6, 2006
Messages
74
k. here goes the entire emailing part of the code

Code:
Dim OutApp As Outlook.Application
    Dim OutMail As Outlook.MailItem
    Dim RecipName As String
    Dim WordApp As Word.Application
    Dim OLbCreated As Boolean
    
    'ignore any errors
    On Error Resume Next
    'attempt to capture an existing instance of Outlook
    Set OutApp = GetObject(, "Outlook.Application")
    're-set to stop on errors
    On Error GoTo 0
    
    'test to see if we successfully captured an existing instance of Outlook
    If OutApp Is Nothing Then
    
        'if no instance of outlook was found, create one
        Set OutApp = CreateObject("Outlook.Application")
        'remember that we created a new instance of outlook
        OLbCreated = True
        
    End If
    
    'create a new mail item (message)
    Set OutMail = OutApp.CreateItem(olMailItem)
    
    'create a new instance of Word... doesn't matter if there is already
    'an instance running, unlike Outlook, Word allows multiple instances
    Set WordApp = CreateObject("word.application")
    
    'set properties of the New Mail Item (Message)
    With OutMail
        .To = "person@place.com"
        .CC = ""
        .BCC = ""
        .Subject = "Wafer Map"
        
        'Body could be text, here we set the Content of an Existing Hardcodesd File
        .Body = Binned_Map_File_Name
        
        'attaches output file
        .Attachments.Add Binned_Map_File_Name
        
        'use EITHER Send or Display Method, not both... send attempts to send in the
        'background, while Display will show the message, requiring the user to
        'click send
        .Send
        
        
    End With
    
    'quit Outlook if we created a new instance, and reset object and item to nothing
    If OLbCreated Then OutApp.Quit
    Set OutMail = Nothing
    Set OutApp = Nothing
    
    'quit the new instance of Word we created, and set object to nothing
    WordApp.Quit False
    Set WordApp = Nothing
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,831
Office Version
  1. 365
Platform
  1. Windows
You could easily change that code to use late-binding by replacing the data type of the variable declarations to Object.

Then you wouldn't need to worry about references.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,364
Messages
5,528,265
Members
409,811
Latest member
pjwhyman

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top