Hi all
I would like to write to excel, i know how to do the basics like the actual writing. But I do no want to specify a cell to write to I want it to go to the next row with no text in the cells can someone help me on this. I would also like it to be done behind the scenes, like when you use stream writer. But I suppose it would have to be opened to find the available row to write in. Help would be much appreciated.
There is a built in function in Excel that will do that but then you would have to be using the Excel Object Model. How about if you use a SQL INSERT INTO statement to add a row? Will it place it at the end of your rows?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Could you show me an example where you click a button, it a number from a text box and puts it into to column A and the next available row.
VB Code:
Dim objExcel As New Excel.Application
objExcel.Visible = True
objExcel.Workbooks.Add()
objExcel.Range("A1").Select()
objExcel.ActiveCell.FormulaR1C1 = "75"
objExcel.Range("B1").Select()
objExcel.ActiveCell.FormulaR1C1 = "125"
objExcel.Range("C1").Select()
objExcel.ActiveCell.FormulaR1C1 = "255"
objExcel.Range("D1").Select()
objExcel.ActiveCell.FormulaR1C1 = "295"
objExcel = Nothing
I have leant ho to do this with a book I have, but what I want to do is open an existing excel file and add to it. It would be a great help if you can give me a very simple example.
How could I tell if when the file is opened whether its read only or not, the reason I ask this is because two people will be writing to this file. But if one has it open the other will not be able to save, I want this to come up with a msg saying already open cannot write until closed. Is this possible?
Its because I forgot the .NET fully qualified object path to the const.
you can do it that way too if its not a new file. If the other user has the workbook open then is it a shared file or are you getting the "Read Only Notification" dialog?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
This file will be on a network, it is basically a quote log. So if when person has got it open it will be read only and the app would now be able to add the quote. So I want to be able to check if it is open so it can be closed. Understand?
Yes I understand but if the workbook is not designated as a Shared Workbook then the users and your code will encounter the message that it is opened Exclusively by another user and if they want to open the file as Read Only.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Yes it does open as Read-Only, if someone else has it open it opens as read only is there a way you can stop this and enable people to save when there are two open.
Also how do you take the content of a cell and then use it, I also want to be able to split this as well eg say the content was EL11-12-RRR and I wanted to take the 11. Can you show me how to do this? Appreciate this help alot.
So just to clarify for me, when this is done. Two people will be able to edit the spreadsheet and save it at different times but it will have both sets of data in. True?
Office 07 is not out yet in the UK dont think, will not be getting it for a while either because it is 70% more expensive here than in the US. Just a massive rip off
I havent been in an environment to be able to test it but its supossed to allow both to make changes. Doesnt specify if it will get refreshed or if they have to reopen it or ?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Can you help me with this? I have got what you have told me working so far. But I now need to write to a cell from two listboxes, this is what I want to happen:
In the cell I want:
The first item in listbox 1 the , and the first item in listbox 2. Then one a new line I would like the second items in the same format.
Hi Rob
I have got this code, I want it to write first line of listbox1 the a , and then the first line of listbox2, then I want it to go to a new line. This is my code, but it overwrites each time obviously, but I didn't know how to do append the cell so wrote this so someone could modify:
Right I have 2 listboxes, on for product and one for the price of the product.
So What I want is to list the contents of the listboxes into a cell.
So for example I will write to A1 with how I want it:
Product 1, Price 1
Product 2 , Price 2
Product 3, Price 3
and so on till all of the items are listed in that cell.
But what happens now is the last product and the last price are the only ones listed, because they overwrite the rest.
Its quite hard to explain, hope this helps you a little more to understand what I want.
Oh ok. Its because you are not changing the cell that you are writting to. You are always writting to the ActiveCell which is not changing. Use an .Offset or just reference the Cells(x, 1) where x is the row number increasing in your loop.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
I want to write to the same cell eachtime so it stays on the same row. Can this be done I want each product and price one a different line thats why I put vbnewline but in the same cell. Can this be done?
Sam
Just reference the cell location as I suggested in a loop that will place each item on a new row. Make a secondary call to place another item on the same row but reference the next column by increasing the Y Cells value.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Ok how about an example of how you want it because I thought you wanted it in each cell and then each row as the record changes. Seems you are asking for everything in a single cell which is what you had in th beginning?[/color]
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Right I have uploaded a spreadsheet as an example, I had to do this is word then copy it across because when you try to press enter in excel it takes you to the cell underneath when I want a new line in that cell. Do you understand what I am after?
I'll look at it in a minute, but did you know that if you press Alt+Enter you will enter a line break and remain editing that same cell instead of moving out of edit mode and mving to the next cell.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
So you want everything in the same cell but 2 items per line in that cell.
Instead of writting to the formula property of the cell in a loop, just write it all out to a string variable in your loop and then assign the cells value to that string variable after the loop is complete.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
I am trying to loop though a spread sheet but I want to be able to use a 1 for the column A instead and so on for the rest.
This is so I can use a variable instead of the actual letter.
This is how I am doing it:
VB Code:
xl.Range(col & frow).Select()
file = xl.ActiveCell.Text
But it comes up with a Comexception was not handled:
System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2146827284
Message="Exception from HRESULT: 0x800A03EC"
Source="Microsoft.Office.Interop.Excel"
StackTrace:
at Microsoft.Office.Interop.Excel.ApplicationClass.get_Range(Object Cell1, Object Cell2)
at itext.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Sam Taylor\My Documents\Visual Studio 2005\Projects\itext\itext\Form1.vb:line 57
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at itext.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Can someone help me with this?
col is the column and frow is the row. The problem is I need them both to be numbers so I can use a loop, but it will not let me because col needs to be a letter I was wondering if there was away around it?