Results 1 to 31 of 31

Thread: [Resolved]How to get save excel file

  1. #1

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Resolved [Resolved]How to get save excel file

    I have an excel file with some data already entered into it.
    now i want to mention row and column of the sheet and want to save whatever in text box ..
    how to do it ..?
    Last edited by vbPoet; Aug 15th, 2005 at 07:58 AM.

  2. #2

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to save in Excel file

    Like i want to save data in textbox Text1 into c:\anyname.xls Row 25 Column C.......

  3. #3
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How to save in Excel file

    ActiveSheet.Cells(2, 2).Formula = InputBox("Enter text")
    This world is not my home. I'm just passing through.

  4. #4
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How to save in Excel file

    Are you coding this using VBA in Excel, or is it a separate VB executable?
    This world is not my home. I'm just passing through.

  5. #5

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to save in Excel file

    Quote Originally Posted by trisuglow
    Are you coding this using VBA in Excel, or is it a separate VB executable?
    It is separate Vb executable ..
    but i want some more assistance how to open excel file with already saved some data and how to save it altogether after adding more data...

  6. #6
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How to save in Excel file

    This should write the entered text into C25 on Sheet1.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim xl As New Excel.Application
    5.   xl.Workbooks.Open "C:\anyname.xls"
    6.   xl.Worksheets(1).Cells(25, 3).Formula = InputBox("Enter Text")
    7.   xl.Save
    8.   xl.Quit
    9. End Sub
    This world is not my home. I'm just passing through.

  7. #7
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How to save in Excel file

    Forgot to mention - you have to go to Project\References and add a reference to "Microsoft Excel Object Library"
    This world is not my home. I'm just passing through.

  8. #8

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to save in Excel file

    But there is one problem with this code..
    it wants to replace original file .
    but i just want to add more data ...
    what to do ..?

  9. #9
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How to save in Excel file

    If you want to add more data then you will have to overwrite the exisiting file. Even if you knew which byte(s) in the file you wanted to change and just wrote over them you would still have to open and close the file (effectively overwriting it).
    This world is not my home. I'm just passing through.

  10. #10

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to save in Excel file

    Previous problem is solved ..
    but here is new one..
    i have some Text data in Text Box when i m saving it to ( 25,1) in excel file only "#VALUE!" is displaying ...
    How to solve this last problem ..?
    Last edited by vbPoet; Aug 15th, 2005 at 05:03 AM.

  11. #11
    Fanatic Member doofusboy's Avatar
    Join Date
    Apr 2003
    Posts
    526

    Re: How to save in Excel file

    You could try changing:

    xl.Worksheets(1).Cells(25, 3).Formula = InputBox("Enter Text")

    to:

    xl.Worksheets(1).Cells(25, 3).Value = InputBox("Enter Text")
    Do canibals not eat clowns because they taste funny?

  12. #12
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How to save in Excel file

    vbPoet, It sounds like the cell type is set up as Numeric rather then General. You can either change the cell type to General, or make sure you only write numeric values into it. From memory, it may also be to do with the value that Excel is trying to display being too wide (ie too many significant digits) to fit in the cell.
    This world is not my home. I'm just passing through.

  13. #13

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to save in Excel file

    Quote Originally Posted by doofusboy
    You could try changing:

    xl.Worksheets(1).Cells(25, 3).Formula = InputBox("Enter Text")

    to:

    xl.Worksheets(1).Cells(25, 3).Value = InputBox("Enter Text")
    of no use ...
    my exact line of code is
    VB Code:
    1. xl.Worksheets(1).Cells(25, 1).Value = Text2

    in Text2 there is nearly 700 words long text ...
    instead of displaying text
    in excel file there is just #VALUE! written.

  14. #14

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to save in Excel file

    Quote Originally Posted by trisuglow
    vbPoet, It sounds like the cell type is set up as Numeric rather then General. You can either change the cell type to General, or make sure you only write numeric values into it. From memory, it may also be to do with the value that Excel is trying to display being too wide (ie too many significant digits) to fit in the cell.
    Yes this is wide data ...
    How to solve this issue ..?

  15. #15
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How to save in Excel file

    Read the Excel help - there is a section under the "#VALUE!" keyword.
    This world is not my home. I'm just passing through.

  16. #16

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to save in Excel file

    Quote Originally Posted by trisuglow
    Read the Excel help - there is a section under the "#VALUE!" keyword.
    The #VALUE! error value occurs when the wrong type of argument or operand is used

    but there is some text only TEXT in text box Text2 .. then what could be the problem ...
    I have checked by inserting small amount of text like 400 characters it is working well but when i insert more than 600 characters it starts to display #VALUE!.

  17. #17
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How to save in Excel file

    Try creating a new spreadsheet and see what happens with that. I've just done exactly this and it works fine with long strings (>600 characters) of text. Let me know the result - if it works then try to work out what the difference is between the spreadsheets.
    This world is not my home. I'm just passing through.

  18. #18

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to save in Excel file

    Quote Originally Posted by trisuglow
    Try creating a new spreadsheet and see what happens with that. I've just done exactly this and it works fine with long strings (>600 characters) of text. Let me know the result - if it works then try to work out what the difference is between the spreadsheets.
    same problem
    #VALUE!
    Last edited by vbPoet; Aug 15th, 2005 at 06:27 AM.

  19. #19

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to save in Excel file

    how long data Excel can support in one cell ..?
    Last edited by vbPoet; Aug 15th, 2005 at 06:19 AM.

  20. #20
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How to save in Excel file

    OK.

    I opened Excel and created a new, blank spreadsheet and saved it as C:\Book1.xls.

    Then I ran this code. None of the cells said #VALUE!

    Can you do exactly the same thing? If you don't get the same result as me then Email me the spreadsheet and I'll try to see what is different.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim xl As New Excel.Application
    5.   Dim vLoop As Long
    6.   Dim vStr As String
    7.   xl.Workbooks.Open "C:\book1.xls"
    8.   For vLoop = 1 To 1000
    9.     vStr = vStr & "word "
    10.     xl.Worksheets(1).Cells(vLoop, 3).Formula = vStr
    11.   Next
    12.   xl.Save
    13.   xl.Quit
    14. End Sub
    This world is not my home. I'm just passing through.

  21. #21

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to save in Excel file

    Quote Originally Posted by trisuglow
    OK.

    I opened Excel and created a new, blank spreadsheet and saved it as C:\Book1.xls.

    Then I ran this code. None of the cells said #VALUE!

    Can you do exactly the same thing? If you don't get the same result as me then Email me the spreadsheet and I'll try to see what is different.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim xl As New Excel.Application
    5.   Dim vLoop As Long
    6.   Dim vStr As String
    7.   xl.Workbooks.Open "C:\book1.xls"
    8.   For vLoop = 1 To 1000
    9.     vStr = vStr & "word "
    10.     xl.Worksheets(1).Cells(vLoop, 3).Formula = vStr
    11.   Next
    12.   xl.Save
    13.   xl.Quit
    14. End Sub


    OOPS
    Your code is showing that u r changing rows as well
    but i want to store 1000+characters in one cell...
    i think that is the difference ...

  22. #22
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How to save in Excel file

    But by the time the code I posted gets to row 1000 vStr will have built up to be 5000 characters long.

    What happened when you tried what I suggested? Were you still getting #VALUE! ?
    This world is not my home. I'm just passing through.

  23. #23

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to save in Excel file

    Your code is working very well ....in Book1.xls
    but #Value! in previous file is still unsolved.

  24. #24
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How to save in Excel file

    So what are the differences between Book1.xls and the other spreadsheet you are using? If you want to post both spreadsheets I'll have a look for you if you can't see a difference.
    This world is not my home. I'm just passing through.

  25. #25

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to save in Excel file

    exactly nothing..
    i cannot post spreadsheets becoz these are sensitive.

  26. #26
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How to save in Excel file

    Well, there must be some difference - what happens when you run my code from post number 21 against your real spreadsheet - do you still get the #VALUE! ?

    What happens if you delete all the data from your sensitive spreadsheet - do you still get the same problem? If so, can you post the spreadsheet with the data deleted?
    This world is not my home. I'm just passing through.

  27. #27

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to save in Excel file

    #21 code was tested with Book1.xls and it was quite good without any error.
    but my original problem is with anyname.xls where data from text2 is going into column "A".
    Text2 contains nearly 25 lines each line contain nearly 5-20 characters.
    and line is separated with Chr(13) & Chr(10).
    I don't know where is problem...
    When i tested by reducing lines of Text2 to 10-13 it works good.but when i increase to 14-25...exactly same error returns back "#VALUE!"
    Really Gettin Mad

  28. #28
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: How to get rid of #VALUE!

    The maximum number of characters a cell in Excel is 32,767... so it does not sound as though the problem is the contents in the cell as it should show this..

    What are the first few charaacters you are sending? If this begins with "=" then that could be the problem, as excel is trying to evaluate a formula.
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  29. #29

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to get rid of #VALUE!

    No text2 contains
    text data only

  30. #30
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: How to get rid of #VALUE!

    Ok then could you post a sample of the text data in text2?
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  31. #31

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to get rid of #VALUE!

    Thank You All
    specially Trisuglow
    it was trimming problem simply Bull****
    Last edited by vbPoet; Aug 15th, 2005 at 08:00 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width