CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Sep 2002
    Location
    Greece
    Posts
    60

    Windows-Office 2000 and XP issues.

    Hello to all,

    Does anyone knows how to find (through VB 6) what kind of Windows version is installed on the target machine? I need to know whether the customer has Windows 2000 or XP.

    Also, I am using Microsoft Office Object Library 9.0 and Microsoft Outlook Object Library 9.0 (as References). Will these libraries exist on a PC with Office XP and Windows XP? If not, what object libraries you have to use in order to work in both Office 2000 and Office XP?

    Thanx in advance.

    vvang10

  2. #2
    Join Date
    Sep 2002
    Location
    England
    Posts
    530
    http://www.zarr.net/vb/download/codedetail.asp?code=251

    The above gives an example which detects (almost) all versions of windows - it cant differentiate between xp and 2000 - Sorry!

    But...

    Why do you need to know this? I thought XP was able to manage and use different versions of the same dll's and ocx's for the different applications that are installed on it?

    Cheers

  3. #3
    Join Date
    Sep 2002
    Location
    Greece
    Posts
    60

    Windows-Office 2000 and XP

    Thanx for the URL. I will check the code provided there.

    First of all, I don't know if XP use different versions of the dll's etc, for each application. Few words for the project I work in:

    I need to send e-mail using, let's say, the Microsoft Outlook 2000 or XP. Probably, the operating system has nothing to do with that and it won't create any problems. But, the Office could create problems because I use as a reference the Object Libraries 9.0 (Outlook 2000 and Office 2000). If Office XP doesn't include the Object Libraries 9.0 then the tool will crash (remember that in the installation package I don't include these Object Libraries because if the target machine uses W2000 then it will overight them and I don't want that). Am I right?

    Basically, my thought was to check the Office version installed and use the appropriate Object Library ( 9.0 if W2K or 10.0 for XP). If you have any better solution/idea for that, it's welcomed.

    Which part of UK are you from?

    vvang10

  4. #4
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167
    The link will provide you the Major and Minor version of the OS. Win2K: Major=5 Minor=0
    WinXP: Major=5 Minor=1

    The get around the office automation object problem, use late binding instead of early binding. Just make sure that you don't use version specific features (meaning, if a functionality is only for Office2K, you app will still able to create the office object but will fail miserably when it executes the feature that does not exist. - error trapping will be a great help at this situation)

    Or after instantiating the office object, check the version and branch out if needed.

    -Cool Bizs

  5. #5
    Join Date
    Sep 2002
    Location
    Greece
    Posts
    60

    Windows-Office 2000 and XP

    OK, I am confused now. By late binding you mean check the office version and then use the appropriate object library? At least that's what I am trying to do. But, the problem is that I have to use Reference and I don't know which one (object 9.0 or 10.0) to use. Here is the example that causes all the trouble (sends automatically an e-mail with attachments through Outlook):

    Dim oExplorer As Outlook.Explorer
    Dim olNS As Outlook.NameSpace
    Dim olFolder As Outlook.MAPIFolder
    Dim oCtl As Office.CommandBarControl
    Dim oPop As Office.CommandBarPopup
    Dim objOutlookMsg As Outlook.MailItem
    Dim oNS As Outlook.NameSpace
    Dim oCB As Office.CommandBar
    Dim oOutlookApplication As Outlook.Application

    Set oOutlookApplication = GetObject(, "Outlook.Application")

    If oOutlookApplication Is Nothing Then

    Err.Clear
    On Error GoTo ErrorHandler

    Set oOutlookApplication = CreateObject("Outlook.Application")
    Set olNS = oOutlookApplication.GetNamespace("MAPI")
    Set olFolder = olNS.GetDefaultFolder(olFolderInbox)
    Set oExplorer = olFolder.GetExplorer
    Set oCB = oOutlookApplication.ActiveExplorer.CommandBars("Standard")
    Set oCtl = oCB.Controls("Send/Receive")

    Set objOutlookMsg = oOutlookApplication.CreateItem(olMailItem)
    objOutlookMsg.To = "xxxx@xxxx.com"
    objOutlookMsg.Subject = "Subject here..."
    objOutlookMsg.Body = " Body Message here..."
    objOutlookMsg.Attachments.Add ("c:\test.doc")
    objOutlookMsg.Send

    oCtl.Execute

    Now some will say "why don't you use something like this":

    Dim oExplorer As Object
    Dim olNS As Object
    Dim olFolder As Object
    Dim oCtl As Object
    Dim oPop As Object
    Dim objOutlookMsg As Object
    Dim oNS As Object
    Dim oCB As Object
    Dim oOutlookApplication As Object

    and then create the objects? Well, I tried but I get errors (Error:ActiveX cannot create object). Coming to that point I thought that it's not acceptable to require from the customer to have Office 2000 and Outlook 2000 installed. So, the solution was to have both references for Office 2000 and XP, check the version on target machine and use the appropriate part code. I don't know a better way.

    vvang10

  6. #6
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167
    Nope, LATE BINDING means DO NOT set the REFERENCE to the Object Library. So you have to DIM all the objects to OBJECT type instead of Outlook.XXXXXX. When CREATEOBJECT() is called, it will use the latest version installed on that particular PC.

    -Cool Bizs

  7. #7
    Join Date
    Sep 2002
    Location
    Greece
    Posts
    60

    Windows-Office 2000 and XP issues

    OK, I see. I tried to give it a shot and changed the declarations to OBJECT. All DIM worked fine apart from the oOutlookApplication. It gives an error in line 6. (Error 450: Wrong number of arguments or invalid property assignment) when I change it to OBJECT from Outlook.Application reference. I don't understand why this error occurs.

    Dim oExplorer As Object
    Dim olNS As Object
    Dim olFolder As Object
    Dim oCtl As Object
    Dim objOutlookMsg As Object
    Dim oCB As Object
    Dim oOutlookApplication As Object

    1. On Error GoTo ErrorHandler

    2. Set oOutlookApplication = CreateObject("Outlook.Application")
    3. Set olNS = oOutlookApplication.GetNamespace("MAPI")

    4. Set olFolder = olNS.GetDefaultFolder(olFolderInbox)
    5. Set oExplorer = olFolder.GetExplorer
    6. Set oCB = oOutlookApplication.ActiveExplorer.CommandBars("Standard")
    7. Set oCtl = oCB.Controls("Send/Receive")

    8. Set objOutlookMsg = oOutlookApplication.CreateItem(olMailItem)
    9.. objOutlookMsg.To = "xxx@xxx.com"
    10. objOutlookMsg.Subject = "Testing..."
    11. objOutlookMsg.Body = "This is a test..."
    12. objOutlookMsg.Attachments.Add ("c:\test.doc")
    13. objOutlookMsg.Send

    14. oCtl.Execute

    15. Set oExplorer = Nothing
    16. Set olNS = Nothing
    17. Set olFolder = Nothing
    18. Set oCtl = Nothing
    19. Set objOutlookMsg = Nothing
    20. Set oCB = Nothing
    21. Set oOutlookApplication = Nothing


    Do you have any ideas of what could cause the error? I hope that it can be solved...

    Cheers

    vvang10

  8. #8
    Join Date
    Jul 2002
    Location
    India
    Posts
    505
    The code worked just fine for me. I am using Windows / Office XP.

    I got an error on line 4 - something about invalid parameters, but I just commented out lines 4 and 5.

    I dont have office 2000 to test that... sorry..

    Line 6 did not give any error.

    Satish

  9. #9
    Join Date
    Sep 2002
    Location
    Greece
    Posts
    60
    And it worked? I mean, was the e-mail send automatically?

  10. #10
    Join Date
    Jul 2002
    Location
    India
    Posts
    505
    Yes .. the email was sent successfully....

    However, i had not checked well about your error.

    I am getting the error now. The first time I tried, my outlook was already open in another window. Somehow this caused your code to work fine and the mail was sent.

    When I closed outlook and then tried, I get the error...

    Satish

  11. #11
    Join Date
    Sep 2002
    Location
    Greece
    Posts
    60

    Windows-Office 2000 and XP issues

    Well, I haven't found a solution to the problem. If you have the oOutlookApplication set to OBJECT and not to Outlook.Application, then you get that error.

    The thing that I don't understand is that since the ...

    Set oOutlookApplication = CreateObject("Outlook.Application")

    ... is done successfully and the object is created then why the error occurs on line?:

    Set oCB = oOutlookApplication.ActiveExplorer.CommandBars("Standard")

    It's not reasonable. Does anyone knows if Office XP (Outlook XP) includes the Microsoft Outlook Object Library 9.0? If so, it might be OK.

    vvang10

  12. #12
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167
    Nope, OfficeXP comes with 10.0 object library.

    I tried this code and it works on XP/OfficeXP:
    Code:
        Dim oExplorer As Object
        Dim olNS As Object
        Dim olFolder As Object
        Dim oCtl As Object
        Dim objOutlookMsg As Object
        Dim oCB As Object
        Dim oOutlookApplication As Object
        
        ' On Error GoTo ErrorHandler
        Set oOutlookApplication = CreateObject("Outlook.Application")
        Set olNS = oOutlookApplication.GetNamespace("MAPI")
        
        Set olFolder = olNS.GetDefaultFolder(6)
        Set oExplorer = olFolder.GetExplorer
        Set oCB = oOutlookApplication.ActiveExplorer.CommandBars("Standard")
        Set oCtl = oCB.Controls("Send/Receive")
        
        Set objOutlookMsg = oOutlookApplication.CreateItem(0)
        objOutlookMsg.To = "john.doe@internet.intranet.com"
        objOutlookMsg.Subject = "Testing..."
        objOutlookMsg.Body = "This is a test..."
        objOutlookMsg.Send
        
        oCtl.Execute
        
        Set oExplorer = Nothing
        Set olNS = Nothing
        Set olFolder = Nothing
        Set oCtl = Nothing
        Set objOutlookMsg = Nothing
        Set oCB = Nothing
        Set oOutlookApplication = Nothing
    -Cool Bizs

  13. #13
    Join Date
    Sep 2002
    Location
    Greece
    Posts
    60

    Windows-Office 2000 and XP issues

    Well, finally I didn't manage to make the Tool work for both Offfice 2000 and XP. The code works well on XP provided that you enter a delay before the line:

    Set oCB = oOutlookApplication.ActiveExplorer.CommandBars("Standard")

    Yes, we need a delay there because the object oOutlookApplication needs some time to be created and therefore you cannot use it (you get error message).

    As far as Office 2000 is concerned I didn't have any luck. I hope the customer is satisfied with the solution provided.

    vvang10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured