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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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.
 
Upvote 0
Thanks Norie,

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

Thanks,
Jake
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
It might help to see some more of the code.:)
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,988
Members
448,538
Latest member
alex78

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
Back
Top