Question vs2010 Excel Problem "Selected.Cells" is always nothing even if I have things.

gta18

New member
Joined
Feb 7, 2014
Messages
2
Programming Experience
Beginner
vs2010 Excel Problem "Selected.Cells" is always nothing even if I have things.

Hi,

I am trying to write a program that can read/write data from excel. I got it working at one time but after closing all the excel windows and restarting it, I am getting "Nothing" on the objApp.selection object that is declared as below....

I wanted to be able to process or work on any excel sheet/workbook that I set focus on.


VB.NET:
Public Class MainSIM    Dim client As DdeClient = New DdeClient("TR1EMCodeEmulator", "Command")e 
    Dim RSclient As DdeClient = New DdeClient("RSLINX", "CLX")
    'Dim objApp As Object
    'Keep the application object and the workbook object global, so you can  
    'retrieve the data in Button2_Click that was set in Button1_Click.
    Dim objApp As Excel.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application")
    Dim oxl As New Excel.Application
    Dim objBook As Excel.Workbook


    Dim objBooks As Excel.Workbooks
    Dim objSheets As Excel.Sheets
    Dim objSheet As Excel._Worksheet
    Dim range As Excel.Range
    Dim fd As OpenFileDialog = New OpenFileDialog()
    Dim strFileName As String

VB.NET:
 Public Sub CheckCEMSheets()        Dim CEMSheets As ScenarioOperator = New ScenarioOperator
        Dim selectedCells
        If objApp.Selection = Nothing Then Exit Sub
        CEMSheets.LookForCEMSceneSheets(objApp.Selection.cells)


        If CEMSheets.CLXCEMSheetPresent Then
            MainSIM.CreateCLXCEM.Enabled = False
        Else
            MainSIM.CreateCLXCEM.Enabled = True
        End If


        If CEMSheets.CLXScenarioSheetPresent Then
            MainSIM.CreateCLXScenarioSheet.Enabled = False
        Else
            MainSIM.CreateCLXScenarioSheet.Enabled = True
        End If


        If CEMSheets.AB5CEMSheetPresent Then
            MainSIM.CreateAB5CEM.Enabled = False
        Else
            MainSIM.CreateAB5CEM.Enabled = True
        End If


        If CEMSheets.AB5ScenarioPresent Then
            MainSIM.CreateAB5ScenarioSheet.Enabled = False
        Else
            MainSIM.CreateAB5ScenarioSheet.Enabled = True
        End If


        If CEMSheets.TCNXCEMSheetPresent Then
            MainSIM.CreateTCNXCEMSheet.Enabled = False
        Else
            MainSIM.CreateTCNXCEMSheet.Enabled = True
        End If


        If CEMSheets.TCNXScenarioSheetPresent Then
            MainSIM.CreateTCNXScenario.Enabled = False
        Else
            MainSIM.CreateTCNXScenario.Enabled = True
        End If
    End Sub
 
Top Bottom