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?
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.
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:
dim xl as new excel.application
set xl = excel.application
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.
Re: Problem initializing excel from Visual Basic IDE
Quote:
Option Compare Database
That's not VB6, are you using VBA in Access? If so this thread should go to VBA Forum.
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.
Re: Problem initializing excel from Visual Basic IDE