Results 1 to 7 of 7

Thread: Problem initializing excel from Visual Basic IDE

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    4

    Problem initializing excel from Visual Basic IDE

    Hi there!

    I am trying to initialize excel aplication from visual basic and then input some data.BUT im guetting an error (that i guess has to do with my previlegies in the PC).Im working with this language now in my new job,and i have some issues with previlegies there.

    HERE IS THE CODE:

    Option Compare Database
    Dim BD As DAO.Database
    Dim content As DAO.Recordset

    Private Sub Main()
    Const ForReading = 1
    Dim fso, fTextFile
    Dim linha As String
    Dim cod_frn As String
    Dim xl As New Excel.Application
    Dim xlw As Excel.Workbook

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fTextFile = fso.OpenTextFile("P:\codigos.txt", ForReading)

    Set BD = OpenDatabase("P:\Access\db1.mdb", False, True)
    Set content = BD.OpenRecordset("B8HJ_DADOS_PEDIDO")

    While content.EOF = False
    While fTextFile.AtEndOfStream <> True
    linha = fTextFile.ReadLine
    value_table = content("ID_ITEM")
    value_table = Replace(value_table, " ", "")

    ' If linha = value_table Then
    'inserir no excel
    Set xlw = xl.Workbooks.Add 'HERE I GET THE ERROR MESSAGE "this feature is not available.For more info,contact the system`s admin"
    xlw.SaveAs ("P:\teste.xls")
    If wb Is Nothing Then
    MsgBox ("Não foi possivel abrir o arquivo" + (sFile))
    xl.Quit
    End If
    ' End If
    Wend
    content.MoveNext
    fTextFile.Close
    Set fTextFile = fso.OpenTextFile("P:\codigos.txt", ForReading)
    Wend

    MsgBox "FIM"
    fTextFile.Close
    End Sub


    so the error message is "this feature is not available.For more info,contact the system`s admin"

    Do you know what kind of error is this?what can i do to fix it?

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Problem initializing excel from Visual Basic IDE

    I pulled this out of your code and it ran fine:

    Code:
    Dim xl As New Excel.Application
        Dim xlw As Excel.Workbook
        
        xl.Visible = True
        
        Set xlw = xl.Workbooks.Add
    That doesn't look like an Excel error message to me. You may be right about privileges.

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

    Re: Problem initializing excel from Visual Basic IDE

    you need to set an object of excel after declaring it, before you can work with it
    try
    vb Code:
    1. dim xl as new excel.application
    2. set xl = 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

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Problem initializing excel from Visual Basic IDE

    Um, no. Line 2 there isn't even legal syntax.

    From what I can find that error comes from an improper or incomplete installation of Excel (or the Office suite). If it is happening at a Terminal Server session you probably have an Office Edition that is not supported under Terminal Services. If this is a standalone PC, Office or Excel were installed with a required feature set to "install on demand" or else Excel is just "advertised" on the machine.

    An admin needs to do a full install of a proper, non-trial Office or Excel package.

  5. #5
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Problem initializing excel from Visual Basic IDE

    Option Compare Database
    That's not VB6, are you using VBA in Access? If so this thread should go to VBA Forum.

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    4

    Re: Problem initializing excel from Visual Basic IDE

    I still cant solve the problem..one time i debug the code and it passed where i should get an error but,the error message came in the other line.Excel is installed in my machine,the version is : Microsoft Office Excel 2003(11.8307.8221) SP3-Part of Microsoft Office Standard Edition 2003.And yes...I am using VBA,please show me the right forum to post and solve my problem,its very important.Thanks for all.

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Problem initializing excel from Visual Basic IDE

    Thread moved.

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