Results 1 to 36 of 36

Thread: [RESOLVED] What is making the difference between how these 2 examples work?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Resolved [RESOLVED] What is making the difference between how these 2 examples work?

    I have an updated VB.NET project that is for the purpose of Excel Automation, but is currently plagued with Error 91s (Object variable or Block variable not set). An example is an Excel Range statement, as follows: "AppExcel.Range(AliasCol & FirstRow).Select()". The ".Select" part of this statement shows as "nothing" and results in an Error 91.

    I have an older VB.NET project that runs fine but has other issues, and I want to replace it. The ".Select" part of the same Excel Range statement shows as "System.Com_Object". I haven't been able to determine precisely which Reference or Imports statement (or something else) is making the difference. What is the best way to determine this?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: What is making the difference between how these 2 examples work?

    The most likely issue is not a Reference etc, but simply that your code is making two big (and unsafe) assumptions.

    The Range object is not a child of the Application, it is a child of a Worksheet, which is a child of a Workbook, and that is the child of the Application.

    While the other objects further up the chain also have a Range object, it is an unsafe way to do things because you are letting Excel guess which Workbook and which Worksheet you wanted to work with - and that can not only change at any moment (due to things the user and/or other programs do), but also the behaviour can vary between computers.

    So, rather than AppExcel.Range use WorksheetObject.Range (assuming you have a variable for the Worksheet, which is advisable), or WorkbookObject.Sheets("SheetName").Range (if you only have a variable for the Workbook), or specify the whole chain: AppExcel.Workbooks("WorkbookReference").Sheets("SheetName").Range

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: What is making the difference between how these 2 examples work?

    unless you wish to show a specific range to the user, you should avoid selecting anyway
    always work with fully qualified ranges, rather than the selection object
    try to avoid references to active anything
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    In the older VB.NET project, 'Public AppExcel' is defined as 'Excel.Application'.

    In the updated VB.NET project, 'Public AppExcel As Excel.Application' gets an exception, 'Type Excel.Application is not defined'. It does, however, accept 'Public AppExcel As Global.Excel.Application', and then accepts 'Public wkbCurrent as AppExcel.Workbooks'.

    A bit later, the statement 'If IsWorkbookOpen(InputInfo, AppExcel.Application) Then' shows 'AppExcel.Application' to be 'nothing'. 'InputInfo' shows to be valid.

    A bit later, the statement 'wkbCurrent = AppExcel.Workbooks(InputInfo.Name)' gets an Error 91. 'AppExcel.Workbooks' shows to be 'nothing'. 'InputInfo.Name' shows to be valid.

    I am trying to follow the advice in post #2, but this obstacle seems to be taking priority. Apparently, I need to figure out how to put some contents into 'AppExcel'. The compiler is happy with "AppExcel', but it seems to be empty.
    Last edited by dick_in_dallas; Jul 17th, 2016 at 02:20 PM.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: What is making the difference between how these 2 examples work?

    That is odd, and could well be an issue with a Reference etc... while it is rather old, the example here could help: http://www.vbforums.com/showthread.p...=1#post2579083

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: What is making the difference between how these 2 examples work?

    'Public AppExcel As Global.Excel.Application'
    while you are dimensioning the variable here are you assigning it a value (object) some place?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    Re posts #2, #3, #5 & #6: while I am dimensioning the variable, I am trying to assign it a value, but am running into a problem:

    If I try to emulate the examples referenced in post #5, ('Dim wkb As Excel.Workbook = AppExcel.Workbooks.Add()'), it seems to add some workbooks, but they are not the workbooks I am looking at in 'frmGetExcel.FileListBox1'. The method goes off the rails at that point.

    In an effort to get it to add the workbooks I am looking at in 'frmGetExcel.FileListBox1', I have tried to borrow code from the older VB.NET project, which works well but has other issues and needs to be replaced. A snippet follows:

    Code:
        Public Sub SetupExcel(wbFilePath As String)
            Where = "[SetupExcel] "
            '
            '   create an Excel instance
            '
            '   this statement will either retrieve an existing Excel instance or create
            '   one if none exists
            '   AppExcel = Global.Excel.Application
            '
            '   this statement will create a new Excel instance
            '
            AppExcel = DirectCast(System.Activator.CreateInstance(Type.GetTypeFromProgID _
                       ("Excel.Application")), Global.Microsoft.Office.Interop.Excel.Application)
    
            Dim books As Excel.Workbooks
            books = AppExcel.Workbooks.Add
            .
            .
            .
    I am currently stuck getting a popup error at the last statement shown above, as follows:
    "[SetupExcel] Error 438 - Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))". I haven't figured out precisely what it is trying to tell me yet.

  8. #8
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: What is making the difference between how these 2 examples work?

    I would think this:

    Code:
    Dim books As Excel.Workbooks
    should be this:

    Code:
    Dim books As Excel.Workbook

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    Re post #8: When I try to change 'Excel.Workbooks' to 'Excel.Workbook' in the updated VB.NET project, it immediately gives me an exception, 'Excel.Workbook is not defined'. However, in the older VB.NET project, it has no problem with changing 'Excel.Workbooks' to 'Excel.Workbook'. The problem is, I cannot find in the older VB.NET project where 'Excel.Workbook' is defined. I have spent a good part of the day looking unsuccessfully for where it is defined. I have checked all of the References for both projects without finding any differences. I have checked the Imports statements for both projects, but have found nothing relevant. I believe 'Excel.Workbook' is just one component of a broader definition that comes from somewhere outside the VB.NET project.

    Where should we expect such a definition to be found? I'm willing to keep looking for it.....
    Last edited by dick_in_dallas; Jul 18th, 2016 at 05:11 PM.

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: What is making the difference between how these 2 examples work?

    AppExcel.Workbooks.Add()
    this should add a new workbook to the workbooks collection, if you want to use an existing workbook you should use the workbooks.open method
    and of course as pointed out by Bryce, you can not assign a single object as a collection object, you must add an object to the collection,

    from the errors, it still appears you have no proper reference to Excel
    you could try
    Code:
    dim book as appExcel.workbook
    book = appexcel.workbook.open("c:\fullpath\filename.xlsx")   ' change file path\name to suit
    as this may circumvent to the lack of reference, though probably not good practice
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    re post #10: Nice try, but no cigar:
    Code:
            Dim books As Excel.Workbook.open(with any contents at all here) gets an error: "Array bounds cannot appear in type specifiers". [<-- whatever that means]      [As a result, 'books" remains undefined.]
            books = AppExcel.Workbooks.add
    Code:
            Dim books As Excel.Workbook.open() gets an error: "'Excel.Workbook.open' is not defined"
            books = AppExcel.Workbooks.add       [no error showing, but 'books' probably remains undefined also]
    I still have no response to my last question in post #9. I am still looking for where Excel.Workbook is defined in the older VB.NET project, thus far with no success. I am still looking...
    Last edited by dick_in_dallas; Jul 19th, 2016 at 09:56 AM.

  12. #12
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: What is making the difference between how these 2 examples work?

    I haven't re-read all the previous posts to know how close to this you've tried:

    Code:
    Dim oXLApp As Excel.Application
            Dim oXLBook As Excel.Workbook
            Dim oXLWS As Excel.Worksheet
            Dim strPath As String
    
            strPath = "c:\yourPath\testDotNet.xlsx"
    
            oXLApp = New Excel.Application
    
            Try
                oXLBook = oXLApp.Workbooks.Open(strPath)
                oXLWS = oXLBook.Worksheets(1)
    But it works for me, using 2010 and Office 2013.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    Re post #12, paraphrasing using my variable names:
    Code:
        Public AppExcel As Excel.Application ([Error #1] Excel.Application is not defined)  <- although it will accept Global.Excel.Application
        Public wkb As Excel.Workbook ([Error #2] Excel.Workbook is not defined)   <- although it will accept Global.Excel.Workbook
        Public wks As Excel.Worksheets(1) ([Error #3] Excel.Worksheet is not defined)   <- although it will accept Global.Excel.Worksheets; (1) (Error #4] Array bounds cannot appear in type specifiers)
    
        Public wbFilePath As String
    
        AppExcel = New Excel.Application
    I am running VS 2010 and Office 2007. I think the errors can be resolved if I can figure out an acceptable way to define the variables with problems.
    Last edited by dick_in_dallas; Jul 19th, 2016 at 03:31 PM.

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: What is making the difference between how these 2 examples work?

    The wks line is extremely different to the example you were shown:
    Code:
            Dim oXLWS As Excel.Worksheet
    (this defines it as a Worksheet)

    Code:
            Public wks As Excel.Worksheets(1)
    (this doesn't define it, and tries to read an item from the collection of sheets in all books in the application)


    What you should have had was:
    Code:
            Public wks As Excel.Worksheet
    (based on the other things you've posted, I assume you'll need to add the Global. prefix)

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    Re post #14: You're right. My bad. I was distracted. Sorry.

    BTW, I am still stuck at the popup error shown in post #7.
    Last edited by dick_in_dallas; Jul 19th, 2016 at 04:51 PM.

  16. #16
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: What is making the difference between how these 2 examples work?

    Code:
    Imports Excel = Microsoft.Office.Interop.Excel
     
    Public Class Form1
    if this is not at the top of the code then you would have all the problems mentioned, confirmed by testing
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    Re post #16: When I try to add that Imports statement, it responds: "Imports alias 'Excel' conflicts with 'Namespace Excel' declared in the root namespace".

    Here's what was there before I tried to add the Imports Excel = ... statement:
    Code:
    Option Infer Off
    Option Strict Off
    Option Explicit On
    
    Imports VB = Microsoft.VisualBasic
    Imports Microsoft.Office.Interop
    Imports System.IO
    Imports System.Runtime.InteropServices
    
    Module UpgradeSupport
    
        Friend ExcelGlobal_definst As New Microsoft.Office.Interop.Excel.Global
    
        <DllImport("user32.dll", SetLastError:=True)>
        Private Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, ByRef IpdwProcessId As Integer) As Int32
        End Function
    End Module
    Should I try to get rid of the 'Namespace Excel' declared in the root namespace?

    Am I correct in concluding the 'Public Class Form1' is just to indicate where the Imports statement should go and is not literal?
    Last edited by dick_in_dallas; Jul 20th, 2016 at 03:29 PM.

  18. #18
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: What is making the difference between how these 2 examples work?

    Am I correct in concluding the 'Public Class Form1' is just to indicate where the Imports statement should go and is not literal?
    yes


    from what i see (note i have not used vb.net previously), you should replace the namespace import with an assignment of the excel namespace, as suggested before, you can then use the Excel object like on testing that import could be in addition to the interop import you already have, though i am not sure there is any advantage or issue doing so

    i created a new project, with a button code
    Code:
    dim appxl as excel.application = new excel.application
    dim wb as excel.workbook = appxl.workbooks.open("somefullpath\myfile.xlsx")
    appxl.visible = true
    '  close off if required
    appxl.quit
    appxl = nothing
    the above is tested to work correctly with a reference to excel and the imports statement as i posted previously

    i can assure you i now have more questions than answers
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  19. #19
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: What is making the difference between how these 2 examples work?

    From a working project, with this reference:

    Microsoft Excel 15.0 Object Library

    Code:
    Imports Microsoft
    Imports Microsoft.Office
    Imports Microsoft.Office.Interop
    Imports Microsoft.Office.Interop.Excel
    
    Public Class Form1
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim oXLApp As Excel.Application
            Dim oXLBook As Excel.Workbook
            Dim oXLWS As Excel.Worksheet
            Dim strPath As String
    
            strPath = "c:\yourPath\testDotNet.xlsx"
    
            oXLApp = New Excel.Application
    
            Try
                oXLBook = oXLApp.Workbooks.Open(strPath)
                oXLWS = oXLBook.Worksheets(1)...

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    I'm getting more and more confused! Every time I try to add an 'Imports Excel = Microsoft.Office.Interop.Excel, It immediately tells me, "Imports alias Excel conflicts with 'namespace Excel' declared in the root namespace", yet I am unable to find where or how 'namespace Excel' is being declared. (I deleted the 'Imports Microsoft.Office.Interop' statement shown in post #17.)
    Last edited by dick_in_dallas; Jul 21st, 2016 at 01:43 PM.

  21. #21
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: What is making the difference between how these 2 examples work?

    What happens when you add the reference, and try the EXACT Imports statements I show in #19?

  22. #22
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: What is making the difference between how these 2 examples work?

    start a new project, with a button, just to test
    add a reference to excel and bryces or my sample code

    personally i prefer late binding, which requires no references and all variables are just object type, one big advantage is that it will then work with any version of excel, not just the version installed on the development machine

    Code:
    dim xl = createobject("excel.application")
    dim wb = xl.workbooks.open("somepath\filename.xlsx")
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    Re post #19 and post #21:
    Since it is my project that I'm trying to get running, and since I have MS Office 2007 installed, I am using the reference to Microsoft Excel 12.0 Object Library. I then commented out all of my Imports statements, and copied the Imports statements verbatim from post #19. I am now getting zero build errors. I am getting a run-time error, but I believe I can deal with that. Thanks for that bit of progress.

    Re post #22:
    The older VB.NET project referred to in post #1 uses early binding and is running fine, but has other issues. However, I am developing a preference for late binding, and the updated VB.NET project referred to in post #1 uses late binding. I have not yet tried the code shown in post #22, because I am trying to stay focused on getting my own project running for now. Thanks for your interest.

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    Some time has passed since post #23, and I'm stuck on a run-time error:

    "[SetupExcel] Err.Number 13, Unable to cast COM object of type
    'System._ComObject' to class type
    'prjEditPath.Microsoft.Office.Interop.Excel.Application'. Instances of types that
    represent COM components cannot be cast to types that do not represent COM
    components, however, they can be cast to interfaces as long as the underlying
    COM component supports QueryInterface calls for the IID of the interface."

    The older VB.NET project referred to in post #1 sails through subroutine SetupExcel without any problems.
    Code:
    	Private Sub SetupExcel(wbFilePath As String)
            Where = "[SetupExcel] "
            '
            '   create an Excel instance
            '
            '   this statement will either retrieve an existing Excel instance or create
            '   one if none exists
    	'	appExcel = New Excel.Application
            '
            '   this statement will create a new Excel instance
            '
            appExcel = DirectCast(System.Activator.CreateInstance(Type.GetTypeFromProgID _
                       ("Excel.Application")), Microsoft.Office.Interop.Excel.Application)
    
    	Dim books As Excel.Workbooks
            books = appExcel.Workbooks
    
            fnum = FreeFile()
            FileOpen(fnum, "C:\Temp\wbFilePath", OpenMode.Output)
            WriteLine(fnum, CStr(wbFilePath))
            FileClose()
    
    		Dim wb As Excel.Workbook = Nothing
    
            Try
                wb = books.Open(wbFilePath)
                'If wb.ReadOnly Then Throw New ReadOnlyException(wbFilePath & " is readonly")
            Catch ex As Exception
                HelperMethods.DisplayException(ex)
                Throw New Exception("Could not open file: " & wbFilePath, ex)
            Finally
                If wb Is Nothing Then
                    Try
                        appExcel.Quit()
                        appExcel = Nothing
                        books = Nothing
                    Catch ex As Exception
                        appExcel = Nothing
                        books = Nothing
                    End Try
                End If
            End Try
    	End Sub
    The updated VB.NET project referred to in post #1 fails on the "AppExcel = DirectCast ..." statement. I have been trying to track down differences between the two VB.NET projects leading up to that statement for quite some time, but have not yet been successful.
    Last edited by dick_in_dallas; Jul 24th, 2016 at 02:19 PM.

  25. #25
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: What is making the difference between how these 2 examples work?

    it is being used in another VBA code that i use everyday with success
    look at the differences between the imports as i suggested and those as posted by bryce

    with the method in post #16, where the imports is assigned to an aliasname, in that example,Excel (can be any name, just Excel seemed to be common usage for an import of office excel), then you can use the aliasname objects as variables (as in post #18)

    if you do not use an alias name, as in bryce's example then you can use objects of the import directly like
    Code:
    Imports Microsoft
    Imports Microsoft.Office
    Imports Microsoft.Office.Interop
    Imports Microsoft.Office.Interop.Excel
    from Imports Microsoft.Office.Interop.Excel
    Code:
    dim app as application = new application
    dim wb as workbook = app.workbooks.open(filename)
    from Imports Microsoft.Office.Interop
    Code:
    dim xlapp as excel.application = new excel.application
    dim wb as excel.workbook = xlapp.workbooks.open(filename)
    If an Imports statement does not include an alias name, elements defined within the imported namespace can be used in the module without qualification. If the alias name is specified, it must be used as a qualifier for names contained within that namespace.
    from https://msdn.microsoft.com/en-us/library/h9st4tss.aspx

    If you use the Imports statement without an alias, you can use all the names in that namespace without qualification, provided they are unique to the project. If your project contains Imports statements for namespaces that contain items with the same name, you must fully qualify that name when you use it. Suppose, for example, your project contained the following two Imports statements:
    VB

    ' This namespace contains a class called Class1.
    Imports MyProj1
    ' This namespace also contains a class called Class1.
    Imports MyProj2

    If you attempt to use Class1 without fully qualifying it, Visual Basic produces an error stating that the name Class1 is ambiguous.
    from https://msdn.microsoft.com/en-us/library/zt9tafza.aspx

    i am not sure that having the multiple level of imports is advantageous or beneficial, especially if using multiple office applications, then you should not import each application, just the interop, unless you used alias names, but i am just learning this stuff
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  26. #26

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    It is now several days since posts #24 and #25. I have made a number of 'improvements'; cleaned up infrastructure; etc., but I am still stuck in the exact same place with the exact same error message as shown in post #24. I still haven't figured out why the older VB.NET project has no problem with this, yet the newer one can't get past it. I'm spinning my wheels, but still on it...

  27. #27
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: What is making the difference between how these 2 examples work?

    why do you need to use directcast? when you can just use = new excel.application
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  28. #28

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    Further re post #24, here are some things I have found:
    (1) 'Excel.Application' is not defined. Earlier, it did accept 'Global.Excel.Application'.
    (2) When I try to declare 'AppExcel', it says "'AppExcel' is already declared as 'Private AppExcel As Object' in this class. I tracked this down, and found it is declared in the Windows.Forms.Designer generated code, but I don't understand why.
    (3) If I comment that declaration out and declare "Public AppExcel' as Global.Excel.Application", the project runs, but gets a run-time error, "Value cannot be null, Parameter name: type".

    Re post #27: The earlier VB.NET project referred to in post #1 (that still runs fine but has other issues) uses the same direct cast statement that is shown in post #24. Also, 'Excel.Application' is not undefined in the earlier VB.NET project, but is undefined in the newer one, and I haven't been able to discover why. (Must be my problem). I am planning to keep beating on this until I somehow prevail.

    I haven't solved the problem yet, but I have come to the conclusion that I must somehow get it to allow me to define 'Excel.Application', and get rid of 'Global.Excel.Application'. Once I succeed in doing that, I expect the other problems will go away. (Of course, there could still be other problems that this one is masking)... Any help in getting 'Excel.Application' defined would be appreciated!
    Last edited by dick_in_dallas; Jul 30th, 2016 at 01:31 PM.

  29. #29
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: What is making the difference between how these 2 examples work?

    can you zip your project and attach?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  30. #30

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    I'll do better than that: I'll zip and attach prjEditPathV2.NET, which is working but has other issues. I will also zip and attach prjEditPath.NET, which is the ancestor of prjEditPathV2,NET, and which I am also trying to update to eventually replace prjEditPathV2.NET. Part of it is working but it is far from finished. It contains a lot of commented-out code and other clutter that will be cleaned up before I'm done.

    It has been a while since I've attached files to a private message and sent it on this forum. It would be helpful if you could refresh me on how it is done.

  31. #31
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: What is making the difference between how these 2 examples work?

    Quote Originally Posted by dick_in_dallas View Post
    It has been a while since I've attached files to a private message and sent it on this forum. It would be helpful if you could refresh me on how it is done.
    You can't put attachments in a private message. The closest you can do is find a hosting site somewhere to put the files, and sent the URL in a pm.

    Alternatively you can attach the files to a post (click on "Go Advanced" then "Manage Attachments"), which allows more people to help you... but does mean more people can see your code, which I get the impression you are concerned about.

  32. #32

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    si_the_geek: Hello!
    I would be happy to attach the files to a post. My only concern about people seeing my code is that right now it contains an awful lot of clutter and is not the neat-looking stuff I like my finished products to be.

    Although prjEditPath.NET and prjEditPathV2.NET are supposed to be pretty similar functionally, a comparison of their Solution Explorers look quite a bit different both in configuration and in content. I have a hunch that the reason one is working and one is not lies somewhere in those differences. Thus far, I have been focusing on the source code and the Imports statements of the various modules. Changing the configuration and the contents of a project at the solution level is way out of my comfort zone, and I feel quite likely to screw it up. Is that something I should be worrying about? Is that something for which I should be asking for help here?
    Attached Files Attached Files
    Last edited by dick_in_dallas; Jul 31st, 2016 at 06:20 PM.

  33. #33

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    Here are the attachments!
    Attached Files Attached Files

  34. #34
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: What is making the difference between how these 2 examples work?

    Is that something for which I should be asking for help here?
    while some here may be proficient to help with this, the fact that they haven't so far indicates they may not, possibly better in the .net forum. i will try opening your project later when i am at a different computer
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  35. #35

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    Re post #34: I'd like to give this thread a bit longer. I put it on 'Office Development' because it primarily has to do with Excel Automation. You might be correct in that I may ultimately need to close this thread and open one on virtually the same subject in the 'VB.NET' arena.

    My current concerns are best articulated in the last paragraph of post #28 and the last paragraph of post #32. If that is a case for the 'VB.NET' folks, so be it.

  36. #36

    Thread Starter
    Addicted Member
    Join Date
    Mar 2015
    Location
    Richardson, TX USA
    Posts
    233

    Re: What is making the difference between how these 2 examples work?

    I have started a new thread with the same title in the VB.NET forum. I will mark this thread RESOLVED to close it out, but it really is not yet Resolved. Thanks to all participants for your help!

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