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
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,303
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
76,303
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
76,303
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
76,303
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.
 

Forum statistics

Threads
1,141,139
Messages
5,704,503
Members
421,353
Latest member
jekoxien15

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top