Results 1 to 10 of 10

Thread: Problem Opening Excel Document

  1. #1

    Thread Starter
    Addicted Member MethadoneBoy's Avatar
    Join Date
    Oct 2001
    Location
    Preferably somewhere between Keira Knightley and Diane Kruger but I'm not fussy
    Posts
    180

    Problem Opening Excel Document

    Hi guys,

    I've been scanning through a few previous threads on accessing and manipulating Excel documents via VBA. I've found a lot of useful information (thanks, btw!) but I've come up against a problem that doesn't seem to be dealt with by anything previously.

    I'd be delighted if anyone here could help. My problem involves opening an Excel document. This is the code I'm currently using -

    Code:
    Public Sub ReadExternal()
    
    Dim appExcel As Excel.Application
    Dim appBook As Excel.Workbook
    Dim appSheet As Excel.Worksheet
    
    End Sub
    Whenever I try to call that method (from a button on a form) I receive the following message -

    Compile Error - User-defined type not defined.
    The compiler seems to take exception to the "Dim appExcel As Excel.Application" line.

    Any advice would be most welcome.

    Thanks.
    "'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."

  2. #2
    Addicted Member
    Join Date
    Jul 2004
    Location
    Mumbai
    Posts
    236

    Re: Problem Opening Excel Document

    hi

    in references select "microsoft excel 9.0 object library". or any version(9.0) will do. the error occurs the type is not defined. in this case the excel dll library is not referenced by the project.
    --Kishore...

  3. #3

    Thread Starter
    Addicted Member MethadoneBoy's Avatar
    Join Date
    Oct 2001
    Location
    Preferably somewhere between Keira Knightley and Diane Kruger but I'm not fussy
    Posts
    180

    Re: Problem Opening Excel Document

    Quote Originally Posted by kishore.kr
    hi

    in references select "microsoft excel 9.0 object library". or any version(9.0) will do. the error occurs the type is not defined. in this case the excel dll library is not referenced by the project.
    Hi,

    Thanks for the help. Sadly, my version of VBA (I'm working from Microsoft Access Office 97) doesn't appear to have a References option in any of the menus. Is there an alternate way of doing it for Office 97 applications?
    "'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."

  4. #4
    Addicted Member
    Join Date
    Jul 2004
    Location
    Mumbai
    Posts
    236

    Re: Problem Opening Excel Document

    are you sure office 97 has no references option. bcos in 2000 its in tools. check help if you can find any other alternative. i am not used to in vba so i dont have exact idea.
    --Kishore...

  5. #5
    Addicted Member
    Join Date
    Jul 2004
    Location
    Mumbai
    Posts
    236

    Re: Problem Opening Excel Document

    hey !!

    i checked google, as far i get it from them., its in the tools->references., the version of the library is 8.0 or lesser. check it out again
    --Kishore...

  6. #6

    Thread Starter
    Addicted Member MethadoneBoy's Avatar
    Join Date
    Oct 2001
    Location
    Preferably somewhere between Keira Knightley and Diane Kruger but I'm not fussy
    Posts
    180

    Re: Problem Opening Excel Document

    I only realised now that the References feature appears to be disabled on my machine.

    I'll report back once I hear from the system administrators here ;-)

    Thanks again!
    "'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."

  7. #7

    Thread Starter
    Addicted Member MethadoneBoy's Avatar
    Join Date
    Oct 2001
    Location
    Preferably somewhere between Keira Knightley and Diane Kruger but I'm not fussy
    Posts
    180

    Re: Problem Opening Excel Document

    Ok. Turns out the feature wasn't disabled - I was still running the program when I tried to access it. *Slaps self on the head*

    Sorry about that. I've now added the reference for Microsoft Excel 8.0 Object Library.

    Still the same error occurs.

    I then tried to add the reference for the Excel 5.0 Library. It then returned an error saying "Name conflicts with existing module, project, or object library."

    Any ideas?
    "'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."

  8. #8
    Addicted Member
    Join Date
    Jul 2004
    Location
    Mumbai
    Posts
    236

    Re: Problem Opening Excel Document

    hi
    try removing all the excel object libraries and then selecting the excel 5.0 library.
    --Kishore...

  9. #9

    Thread Starter
    Addicted Member MethadoneBoy's Avatar
    Join Date
    Oct 2001
    Location
    Preferably somewhere between Keira Knightley and Diane Kruger but I'm not fussy
    Posts
    180

    Re: Problem Opening Excel Document

    Tried that as well and no such luck, unfortunately. It's very perplexing.
    "'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."

  10. #10
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Problem Opening Excel Document

    Does the workbook have any sensitive data? If not, put it in a zip file and post up. We could perhaps check it to our versions.

    References are in the VBA editor. The Excel one should already be loaded as you are in Excel. You may need the New command word:
    Code:
    Dim appExcel As New Excel.Application
    Dim appBook As new Excel.Workbook
    Dim appSheet As new Excel.Worksheet
    This is if you want a new instance.

    If you are in Excel and want to open another workbook, use application.workbooks.add (check the help file on it).

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

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