Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 10th, 2006, 12:21 PM
Authorized User
 
Join Date: Oct 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Open up Worksheet

Good Afternoon,

When I open a workbook in Excel 2003, it can't find the project, it says cannot find project when the user enables teh macros. It works fine in Excel 97.

How do I fix this?????

Kind regards,

Alan
 
Old February 10th, 2006, 12:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You'll have a missing VBA project reference (probably!).

Go to the VBE open up the references dialog box (Tolls -> References...). There will be a series of checked items. If the problem is as I suspect then at least one of them will say "MISSING: ...". Uncheck the missing items and recheck the similarly named items from the list of unchecked items below. Hit ok and you should be good to go.

Maccas

 
Old February 10th, 2006, 12:53 PM
Authorized User
 
Join Date: Oct 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the 2 missing references are Microsofy Office 8.0 Library and Outlook 98

How do i get these? They were not in the list of available references
 
Old February 10th, 2006, 01:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Is there not a Microsoft Office 11.0 Object Library and a Microsoft Outlook 11.0 Object Library (assumes you're using Office 2003 - change the number for a diff version of Office)?

Failing that you could look for the libraries by pressing the Browse... button and looking for the DLL files in "C:\Program Files\Common Files\Microsoft Shared\OFFICE11".

Failing that you could rewrite the code to implement late binding rather than early binding - they you don't need references.

Maccas

 
Old February 13th, 2006, 01:52 PM
Authorized User
 
Join Date: Oct 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The worksheet has the Office 11 Object library. How would I go about re-writing the code to implement late binding as I assume this would be an issue for all users using office 2003 in our company

Any help is greatly appreciated
 
Old February 13th, 2006, 02:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Alan,

If everyone in the office is using Office 2003 then it will be far easier to just update the references to the OFFICE 11.0 libraries and release a new version of the file. This means you wan't have to recode.

If you want to implement late binding then the best way to demonstrate how to do it is with a quick example. The basic rules here are: remove all the references to the external libraries, rewrite the declarations of all external library generated objects to declare them as Object, rewrite the initial object creation lines from
Code:
Set MyObj = New ExtLib.NewObj
to
Code:
Set MyObj = CreateObject("ExtLib.NewObj")
& get rid of any user-friendly constants and replace them with the underlying numbers.

The following bit of code demonstrates two subroutines which demonstrate Early and Late binding to open Outlook from Excel and create a new message. I've written this on the fly and not debugged so it comes with a health warning but it should be close enough.

Code:
Sub EarlyBinding(msgTo As String, msgSubj As String, msgBody As String)

Dim objOutlook As Outlook.Application
Dim objExplorer As Outlook.Explorer
Dim objNs As Outlook.Namespace
Dim objMsg As Outlook.MailItem

    Set objOutlook = New Outlook.Application

    Set objExplorer = OlApp.ActiveExplorer
    If TypeName(objExplorer) = "Nothing" Then
        Set objNs = OlApp.GetNamespace("MAPI")
        objNs.Logon
    End If

    Set objMsg = objOutlook.CreateItem(olMailItem)
    objMsg.to = msgTo
    objMsg.Subject = msgSubj

    If Len(msgBdy) > 0 Then
        If HTMLFmt = False Then
            objMsg.body = msgBdy
        Else
            objMsg.HTMLBody = msgBdy
        End If
    End If

End Sub

Sub LateBinding(msgTo As String, msgSubj As String, msgBody As String)

Dim objOutlook As Object
Dim objExplorer As Object
Dim objNs As Object
Dim objMsg As Object

    Set objOutlook = CreateObject("Outlook.application")

    Set objExplorer = OlApp.ActiveExplorer
    If TypeName(objExplorer) = "Nothing" Then
        Set objNs = OlApp.GetNamespace("MAPI")
        objNs.Logon
    End If

    Set objMsg = objOutlook.CreateItem(0) 'Const olMailItem = 0
    objMsg.to = msgTo
    objMsg.Subject = msgSubj

    If Len(msgBdy) > 0 Then
        If HTMLFmt = False Then
            objMsg.body = msgBdy
        Else
            objMsg.HTMLBody = msgBdy
        End If
    End If

End Sub
Hope this helps,
Maccas






Similar Threads
Thread Thread Starter Forum Replies Last Post
Refresh worksheet on open paul20091968 Excel VBA 0 May 10th, 2006 07:53 AM
finding a worksheet ozPATT Excel VBA 4 November 16th, 2005 10:54 AM
Send Worksheet alannoble26 Excel VBA 3 November 2nd, 2005 01:04 PM
Setting Worksheet name marcusfromsweden XSLT 0 September 19th, 2005 11:50 AM
how to name worksheet by Month yylee Excel VBA 2 April 10th, 2004 01:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.