Hi Hope some body can help with this: -
I have just installed Visual Studio 2005 Professional onto my PC and want to write an application that opens an Excel spreadsheet and reads data from a specific range in the sheet.
Problem is I cannot seem to import the Excel objects into the program. Looking around on the net I have found some code like this: -
ImportsExcel = Microsoft.Office.Interop.Excel
ImportsOffice = Microsoft.Office.Core
However this just produces an error to the effect that the office and excel lines are not recognised.
Can anyone tell me what the correct import would be to enable me to use the excel objects?
Many thanksTuesday, August 22, 2006 6:33 PM
I also have the same requirement , that is populate an excel spread-sheet through visual basic , but the same problem persist for me also , I tried the link Jonathan Aneja have provided , but it's not working as of now. So can anybody kindly provide me the details required to add a reference to "Microsoft Excel 11.0 Object Library".
Thanks In Advance,
LokeshWednesday, September 27, 2006 12:35 PM
Thanks for your comment and I was able to add reference for "Microsoft Excel 11.0 Object Library" , but even after adding a reference , I was able to see only "Microsoft.Office.Core" and "Microsoft.Office.Interop" was not present. So can you kindly help me out getting this done.
LokeshThursday, September 28, 2006 5:40 AM
I just ran this in VB express and it worked so give it a try: -
Create a form with a button and a checkbox called FillWithStrings
Then add this code to the form: -
ImportsOffce = Microsoft.Office.Core
objApp =New Excel.Application()
objBooks = objApp.Workbooks
objBook = objBooks.Add
objSheets = objBook.Worksheets
objSheet = objSheets(1)'Get the range where the starting cell has the address 'm_sStartingCell and its dimensions are m_iNumRows x m_iNumCols.
range = objSheet.Range("A1", Reflection.Missing.Value)
range = range.Resize(5, 5)If (Me.FillWithStrings.Checked = False) Then
saRet(iRow, iCol) = iRow * iColNext iCol Next iRow 'Set the range value to the array.
range.Value = saRetElse 'Create an array. Dim saRet(5, 5) As String 'Fill the array. Dim iRow As Long Dim iCol As Long For iRow = 0 To 5
saRet(iRow, iCol) = iRow.ToString() +"|" + iCol.ToString() Next iCol Next iRow 'Set the range value to the array.
range.Value = saRetEnd If 'Return control of Excel to the user.
objApp.UserControl =True 'Clean up a little.
objBooks =Nothing End Sub
Hope it helps
BradleyTuesday, October 03, 2006 5:13 PM
This works fine , thanks for your kind reply and the query I have raised in my last post was the Microsoft.Office.Core is getting imported but Microsoft.Office.Interop interface was not even present ( I'm using Visual Studio 2005 Proffessional Edition ) . Anyway I was able to accomplish the requirement with the code you have given , again thanks a lot for your response.
Thanks & Regards,
Lokesh RWednesday, October 04, 2006 12:51 PM