|
-
Feb 7th, 2012, 10:10 AM
#1
Thread Starter
New Member
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?
-
Feb 7th, 2012, 01:07 PM
#2
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.
-
Feb 7th, 2012, 03:38 PM
#3
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
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
-
Feb 7th, 2012, 09:14 PM
#4
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.
-
Feb 7th, 2012, 09:40 PM
#5
Re: Problem initializing excel from Visual Basic IDE
That's not VB6, are you using VBA in Access? If so this thread should go to VBA Forum.
-
Feb 8th, 2012, 05:22 AM
#6
Thread Starter
New Member
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.
-
Feb 16th, 2012, 02:24 AM
#7
Re: Problem initializing excel from Visual Basic IDE
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|