+ Reply to Thread
Results 1 to 11 of 11

Compile Errors - Is it possible to ignore them?

  1. #1
    Registered User
    Join Date
    06-01-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    47

    Exclamation Compile Errors - Is it possible to ignore them?

    Hi, and sorry for the long question..

    My issue is that I need a number of applications to work in Windows XP (Office 2003, and an internal program), and also be able to work in Windows 7 (Office 2010, and an updated internal program). - I need each application (Excel/Access Macro) as a single file, and I need each file to work, regardless of what OS/office/application version the user has.

    I already implemented code to add/remove the appropriote references (based on GUID), as well as code to determine the Office version (If a user has Office 2010, they also have Windows 7 and the updated program, while if a user has Office 2003, they have XP and the old program).

    --

    The issue I have right now is: I have two modules - One module that works in Windows XP with the old program, and one module that works in Windows 7 with the new program.

    If I add them both to the macro, I get compile errors and am unable to even run the macro (my initial goal was to basically do an 'if WinXP then use old module, if Win7 then use new module).

    I know the best solution to this is to use a seperate workbook and read from there - this is not possible with the way our security is set up.

    The solution needs to be within one Excel workbook.

    --

    So - basically, is there a way to somehow ignore these compile errors? or to (with code) comment out or delete a module (perhaps on workbook open?) Maybe there's an even simpler solution..

    Is there some way I can combine both modules into a class module, and only use the parts I require based on Office version?
    Last edited by Shane O; 07-13-2011 at 09:45 AM.

  2. #2
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    426

    Re: Compile Errors - Is it possible to ignore them?

    you can use something like this:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    06-01-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    47

    Re: Compile Errors - Is it possible to ignore them?

    Quote Originally Posted by mohd9876 View Post
    you can use something like this:
    Please Login or Register  to view this content.
    Thanks for the response,

    While this works for subs and functions - it doesn't work for private/public variables defined outside of subs/functions. (In this case , objects).

    Is there any way to define an object (private/public) inside a sub/function? Or is there a way I can use something similar to the #If.. #End If ?
    Or is there - in fact - an even simpler solution?

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Compile Errors - Is it possible to ignore them?

    What objects do you mean?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    06-01-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    47

    Re: Compile Errors - Is it possible to ignore them?

    Quote Originally Posted by royUK View Post
    What objects do you mean?
    Objects that are used to connect with the other program... so, in Windows XP:

    Please Login or Register  to view this content.
    And in Windows 7:

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    426

    Re: Compile Errors - Is it possible to ignore them?

    As far as I know you can use #If.. outside subs and functions

  7. #7
    Registered User
    Join Date
    06-01-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    47

    Re: Compile Errors - Is it possible to ignore them?

    Quote Originally Posted by mohd9876 View Post
    As far as I know you can use #If.. outside subs and functions
    Looks like you're right, however you still can't declare variables within an if, unfortunately

  8. #8
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    426

    Re: Compile Errors - Is it possible to ignore them?

    well fortunately you are wrong about this, you can declare variables within a #If

  9. #9
    Registered User
    Join Date
    06-01-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    47

    Re: Compile Errors - Is it possible to ignore them?

    Quote Originally Posted by mohd9876 View Post
    well fortunately you are wrong about this, you can declare variables within a #If
    Hmm, didn't know that, but you're right you can declare variables within an #IF, thanks!

    I can't seem to get this to work:

    Please Login or Register  to view this content.
    It keeps saying "Invalid use of object" and highlighting DualWindows
    Last edited by Shane O; 07-13-2011 at 09:42 AM.

  10. #10
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    426

    Re: Compile Errors - Is it possible to ignore them?

    actually no it won't because you have some compiler constants that you are limited to.
    you could do this:

    [code]
    #If VBA7 Then
    Private objSystem As Attachmate_Reflection_Objects_Framework.ApplicationObject
    #Else
    Private objSystem As ExtraSystem
    #End If

  11. #11
    Registered User
    Join Date
    06-01-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    47

    Re: Compile Errors - Is it possible to ignore them?

    Quote Originally Posted by mohd9876 View Post
    actually no it won't because you have some compiler constants that you are limited to.
    you could do this:

    [code]
    #If VBA7 Then
    Private objSystem As Attachmate_Reflection_Objects_Framework.ApplicationObject
    #Else
    Private objSystem As ExtraSystem
    #End If
    Thanks a bunch! This looks like it's working!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1