Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulate MS-Excel file

Status
Not open for further replies.

arlequin

Programmer
Sep 21, 1999
232
UY
Hello, folks!

I am trying to manipulate a MS-Excel workbook under Visual FoxPro version 7.0

For testing purposes I am programming a little procedure using VBA inside a new blank MS-Word document.
I have the following code:
Code:
Sub ArchivoExcel()
  Dim obj As Excel.Application
  Dim ShhetCount As Integer

  obj.Workbooks.Open ("Abitab.xls")
  SheetCount = obj.Sheets.Count

  TextBox1.Text = Str(SheetCount)

End Sub

But I am getting Runtime error 91 at the line that tries to open the Excel file.

The whole idea is to open an Excel file under VFP and then count how many sheets it has in order to process one sheet each time. This 'process' would involve dumping the sheet's values into a temporal DBF and then bind it to a grid, allowing the user to modify it.
I don't want to create a new Excel Workbook, I want to load an Excel file and then count how many sheet it has.

Thanks a lot,

Arlequín
arlequin@montevideo.com.uy
 
a: You need to Set the excel app
b: you need to provide the full path of the file in the workbook.open call eg
obj.Workbooks.Open ("C:\Home\Abitab.xls")
c: you need to use Dim sheetcount not shhetcount (typo I'm sure)

anyways - here's some sample code that I use to open an excel file from access - should be exactly the same from word or FoxPro

Dim objExcelApp As New Excel.Application
Dim objExcel As Object
'create Excel
Set objExcelApp = New Excel.Application
'open file
Set objExcel = objExcelApp.Workbooks.Open("D:\booknew.xls")
objExcelApp.Visible = True

Rgds
Geoff
Si hoc legere scis, nimis eruditionis habes
 
Geoff:

Now it's like crystal to me.
Thanks a lot.

Regards,

Arlequín
arlequin@montevideo.com.uy
 
I am trying to open an Excel file w/ a macro so that I can run the macro when I export my query out of Access to Excel, I want the following to happen:

1. Open the wkbk containing my macros minimized
2. Export the query to a new workbook (this is working w/ the transferspreadsheet command)
3. Maybe use Sendkeys to run the macro in on the new file.

I tried copying the code above and I keep getting this error:Compile Error: User-defined type not defined and the New Excel.appliation is the line that is highlighted.

I have Access 10.0 object library and DAO 3.6
I tried adding Excel 10.0 but it gave me an error conflicting references. How do I make this work?
 
for starters, don't piggyback threads - please start a new one

Rgds
Geoff
Si hoc legere scis, nimis eruditionis habes
 
xlbo - did you not read my post? It is referencing the very code in this thread! For starters, your here to help so leave the sarcasm offline!
 
kpal29

xlbo was not being sarcastic. He simply asked - rather politely I think - that you start a new thread in order to keep things organized (in accordance with the site policies).

So, please, start a new thread with the code you are using and repost it... who knows, you may get a better suited answer to your specific question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top