Results 1 to 10 of 10

Thread: [RESOLVED] What is wrong in this expression

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2011
    Location
    Greece
    Posts
    164

    Resolved [RESOLVED] What is wrong in this expression

    Hi

    I have a excel sheet there I will copy a cell d:58 to a label17
    tried serveral suggestions on internet but I can't get it to work

    Code:
    Dim objXl As New Excel.Application
    Dim objWb As Excel.Workbook
    Dim xlTmp As Excel.Application
    Set xlTmp = Excel.Application
    
    If File3.FileName = Left$(File3.FileName, 4) Then
       File3.FileName = File3.FileName
       End If
    
    Dim AppExcel        As Object
        
        Set AppExcel = CreateObject("Excel.application")
        
        AppExcel.Workbooks.open Dir2.Path + "\kundfaktura\" + File3.FileName
        
       AppExcel.Visible = True
      
       Label17.Caption = objWb.Worksheets("blad1").Range("D58").Value ' runtime error 91
    Help please

  2. #2
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: What is wrong in this expression

    Your if statement does not make sense, it should be removed. When you want to add a string to a string do no use + use & instead. Does your file load into your excel sheet?

  3. #3
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Re: What is wrong in this expression

    if you have already declared
    Code:
    Dim objXl As New Excel.Application
    then again declaring xlTmp as excel.application is also does not make sense . please read basic things like variable , object and how to work on excel .google it .and you will get more detail and idea .and then come back here .

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: What is wrong in this expression

    Also, to fix your '91' problem, try this:
    Code:
        Dim AppExcel As Excel.Application
        Dim objWb As Excel.workbook
        Set AppExcel = CreateObject("Excel.Application")
        Set objWb = AppExcel.Workbooks.Add
        Set objWb = GetObject(Dir2.Path & "\kundfaktura\" & file3.FileName)
        Label17.Caption = objWb.Worksheets("blad1").Range("D58").Value

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2011
    Location
    Greece
    Posts
    164

    Re: What is wrong in this expression

    Quote Originally Posted by SamOscarBrown View Post
    Also, to fix your '91' problem, try this:
    Code:
        Dim AppExcel As Excel.Application
        Dim objWb As Excel.workbook
        Set AppExcel = CreateObject("Excel.Application")
        Set objWb = AppExcel.Workbooks.Add
        Set objWb = GetObject(Dir2.Path & "\kundfaktura\" & file3.FileName)
        Label17.Caption = objWb.Worksheets("blad1").Range("D58").Value

    THANKS very much it realy works

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: What is wrong in this expression

    Now, try to figure out WHY. :-) Compare that with yours.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2011
    Location
    Greece
    Posts
    164

    Re: What is wrong in this expression

    Okej I whas in little hurry
    but after I gone true the code I changed a line



    Dim AppExcel As Excel.Application
    Dim objWb As Excel.workbook
    Set AppExcel = CreateObject("Excel.Application")
    Set objWb = AppExcel.Workbooks.Add

    '''''''''''''********* 'Set objWb = GetObject(Dir2.Path & "\kundfaktura\" & file3.FileName)

    Set objWb = Workbooks.open(Dir2.Path & "\kundfaktura\" & File3.FileName)

    Label17.Caption = objWb.Worksheets("blad1").Range("D58").Value
    then it's works fine all time

    THANKS
    Last edited by Bonzo2008; Jun 2nd, 2014 at 09:38 AM.

  8. #8
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: What is wrong in this expression

    NP----please mark this thread as Resolved (Thread Tools menu)

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2011
    Location
    Greece
    Posts
    164

    Re: What is wrong in this expression

    HI again

    a little problem
    when I have collect say file one then a msg box

    saying Microsft Excel

    will you save changes to file with number 2222.xls
    how can I get rid of this in the file3_dblclick

  10. #10
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: What is wrong in this expression

    Can you mark this thread as Resolved? Then open a NEW thread with a topic more suited to your NEW problem? Also, it would be of TREMENDOUS value if you could attach your project (or at least the applicable code that does not work)?

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