Results 1 to 9 of 9
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stupid Qst excel and VB (2000 sr-1)

    Correct this code to get value from sheet in wbook of dir (without open workbook) ???
    Have error, naturally

    Sub MAIN()

    Dim XlApp1 As Excel.Application
    Dim XlBook1 As Excel.Workbook
    Dim XlSheet1 As Excel.Worksheet
    Dim PercorsoNome, TEST1 As String

    Set XlApp1 = CreateObject("Excel.Application")
    PercorsoNome = "GCD01F4500DATIPUBBLICAAPPLICAZIONIANTIRICICLAGGIO _MASTER_TEST_3.xls"
    Set XlApp1 = New Excel.Application
    Set XlSheet1 = XlBook1.Worksheets("LUSTSTP")

    TEST1 = XlSheet1.Range("A1")

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Stupid Qst excel and VB (2000 sr-1)

    1) You shouldn't set XlApp1 twice. Use one of the two lines and delete the other one.

    2) You don't set XlBook1. You must do this after setting XlApp1 and before setting XLSheet1.

    Set XlBook1 = XlApp1.Workbooks.Open(PercorsoNome)

    3) You don't use the variable TEST1.

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stupid Qst excel and VB (2000 sr-1)

    First error solved...
    But in:
    Set XlBook1 = XlApp1.Workbooks.Add(PercorsoNome)
    if i use ADD or OPEN the code open the wbook, i want work without to open wbook...

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Stupid Qst excel and VB (2000 sr-1)

    You cannot get the value of cells without opening the workbook in Excel.

  5. #5
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stupid Qst excel and VB (2000 sr-1)

    Dubt...
    I know is possible to declare with Global statement the Dim to connect Excel object and maintain this dim dor all part omy project...
    But, for Set statement is possible to use a Global Set or i must insert this Set in all my macro when use Excel Object?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Stupid Qst excel and VB (2000 sr-1)

    If you declare XlApp1 as a global variable, you only have to set it once, the first time you need it. It will then be available for use in all procedures and functions in your project, until you explicitly use XlApp1.Quit or set the object to Nothing. Also, if an unhandled error occurs, the object will be set to Nothing, so you should include error handling in your code.

  7. #7
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stupid Qst excel and VB (2000 sr-1)

    ok, tks for note.

  8. #8
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stupid Qst excel and VB (2000 sr-1)

    Hans wath you think about?:

    instead:
    Dim xlapp As excel.application
    dim xlbook as excel.workbook

    sel xlapp = new excel.application
    set xlbook = xlapp.workbooks.open("C:test.xls")

    this:

    Dim xlapp As excel.application
    dim xlbook as excel.workbook

    sel xlapp = new excel.application
    set xlbook = GetObject ("C:test.xls")

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Stupid Qst excel and VB (2000 sr-1)

    The line

    set xlbook = GetObject ("C:test.xls")

    will also open C:Test.xls in Excel. forget about trying to read an Excel workbook without opening it in Excel.

Posting Permissions

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