|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Excel Range will not put data into correct CellI am trying to populate data into cells in an Excel spreadsheet using Range.Value. No matter what cell I give as an argument to the Range object, Excel always puts the value in "A1". Here is the code I am having problems with. I am not getting any errors. oWBK = oXL.Workbooks.Open("C:\Data.xls") oWS = oXL.Worksheets(1) oWS.Range("C3").Value = "PUT IT IN THE RIGHT SPOT!!!" The resulting Excel sheet will have the text "PUT IT IN THE RIGHT SPOT!!!" in Cell "A1". What am I doing wrong? Thanks Hi,
Although this is probably for VBNet, will asking this kind of questions first in the one of the most active newsgroups microsoft.public.excel.programmer Give you an better change on an answer and if it than does not fit in VBNet ask it here. I hope this helps, Cor Show quoteHide quote "XxLicherxX" <goldhor***@aol.com> schreef in bericht news:1137776909.792975.17690@g43g2000cwa.googlegroups.com... > Hello everyone - new to VB.net working with Excel > > I am trying to populate data into cells in an Excel spreadsheet using > Range.Value. No matter what cell I give as an argument to the Range > object, Excel always puts the value in "A1". > > Here is the code I am having problems with. I am not getting any > errors. > > oWBK = oXL.Workbooks.Open("C:\Data.xls") > oWS = oXL.Worksheets(1) > oWS.Range("C3").Value = "PUT IT IN THE RIGHT SPOT!!!" > > The resulting Excel sheet will have the text "PUT IT IN THE RIGHT > SPOT!!!" in Cell "A1". > > What am I doing wrong? > > Thanks > How about this syntax:
if you can gain access to the Cells collection, you should be able to do something like: Cells(row, col).Value = "My good value" HTH Steve Show quoteHide quote "XxLicherxX" <goldhor***@aol.com> wrote in message news:1137776909.792975.17690@g43g2000cwa.googlegroups.com... > Hello everyone - new to VB.net working with Excel > > I am trying to populate data into cells in an Excel spreadsheet using > Range.Value. No matter what cell I give as an argument to the Range > object, Excel always puts the value in "A1". > > Here is the code I am having problems with. I am not getting any > errors. > > oWBK = oXL.Workbooks.Open("C:\Data.xls") > oWS = oXL.Worksheets(1) > oWS.Range("C3").Value = "PUT IT IN THE RIGHT SPOT!!!" > > The resulting Excel sheet will have the text "PUT IT IN THE RIGHT > SPOT!!!" in Cell "A1". > > What am I doing wrong? > > Thanks > Hey Guys,
Thanks for your responses. I have worked on it a little more and the problem seems to be with the way I create the Excel file. I was doing this: FileOpen(1,"C:\data.xls") FileClose(1) when I commented this stuff out, everything started working correcly, however, I need to be able to create a new file from this application. So I tried using Sub CreateXLFile() Dim oExcel = CreateObject("Excel.Application") With oExcel .SheetsInNewWorkbook = 3 oExcel = .Workbooks.Add .Save("C:\Data.xls") .Quit() End With End Sub That does not work. It creates the file just fine, but does not write to it. This is what I am using to write to the file: (Same as Above) oWBK = oXL.Workbooks.Open("C:\Data.xls") oWS = oXL.Worksheets(1) oWS.Range("C3").Value = "PUT IT IN THE RIGHT SPOT!!!" I then open the excel file and it is blank. The only time I can get this to work correctly is if I manually create the file using Windows Explorer ("Right Click -> Excel File, etc). What am I doing wrong again? Thanks Ok, I looked around a bit more and it is in fact writing data, however
it is saving it to the My Documents folder under Book1.xls, Book2.xls, etc. This doesn't make any sense to me. I never specify the My Documents directory anywhere in the program. Also when the program is running I get a prompt telling me that "C:\Data.xls" already exists and would I like to replace it. This might help
http://support.microsoft.com/?scid=kb;EN-US;301982 If not I have demo code, let me know. Show quoteHide quote "XxLicherxX" <goldhor***@aol.com> wrote in message news:1137776909.792975.17690@g43g2000cwa.googlegroups.com... > Hello everyone - new to VB.net working with Excel > > I am trying to populate data into cells in an Excel spreadsheet using > Range.Value. No matter what cell I give as an argument to the Range > object, Excel always puts the value in "A1". > > Here is the code I am having problems with. I am not getting any > errors. > > oWBK = oXL.Workbooks.Open("C:\Data.xls") > oWS = oXL.Worksheets(1) > oWS.Range("C3").Value = "PUT IT IN THE RIGHT SPOT!!!" > > The resulting Excel sheet will have the text "PUT IT IN THE RIGHT > SPOT!!!" in Cell "A1". > > What am I doing wrong? > > Thanks >
Best approach - databound controls & ADO.NET
CHANGING DATA TYPE Get information about Dial Up connections? Changed Date on PC, now project doesn't compile source code changes Maintaining a response user interface NetUserChangePassword Module not found?? How to close an application?? Parsing a string - please help Maximized MDI childforms.... Anyone? Simple mask Edit for Hours:Minutes |
|||||||||||||||||||||||