Saving ComboBoxes and TextBoxes to an Excel book

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 1346 Views - Last Post: 08 March 2013 - 06:36 AM Rate Topic: -----

#16 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

Re: Saving ComboBoxes and TextBoxes to an Excel book

Posted 19 February 2013 - 06:07 AM

View Postandrewsw, on 18 February 2013 - 11:33 AM, said:

I hope that modi123_1 won't mind me re-quoting his earlier post, as he states it very well:

Quote

"this code does not work" - how? In what way? Is there an exception? If so what is the text and what line is the exception on? Is it not performing as expected? If so what is it doing/what results is it providing, and what were you expecting? The more you can tell us the better we are at helping you.

and, of course, we would need to see relevant code.


Here is my coding:
oSheet.Range("A5").Value = ComboBox1.SelectedItem.ToString()
        oSheet.Range("A6").Value = ComboBox2.SelectedItem.ToString()
        oSheet.Range("A7").Value = ComboBox3.SelectedItem.ToString()
        oSheet.Range("A8").Value = ComboBox4.SelectedItem.ToString()
        oSheet.Range("A9").Value = ComboBox5.SelectedItem.ToString()
        oSheet.Range("A10").Value = ComboBox6.SelectedItem.ToString()
        oSheet.Range("A11").Value = ComboBox7.SelectedItem.ToString()
        oSheet.Range("A12").Value = ComboBox8.SelectedItem.ToString()
        oSheet.Range("A13").Value = ComboBox11.SelectedItem.ToString()
        oSheet.Range("A14").Value = ComboBox12.SelectedItem.ToString()
        oSheet.Range("A15").Value = ComboBox13.SelectedItem.ToString()
        oSheet.Range("A16").Value = ComboBox14.SelectedItem.ToString()
        oSheet.Range("A17").Value = ComboBox10.SelectedItem.ToString()
        oSheet.Range("A18").Value = ComboBox9.SelectedItem.ToString()



I want to be able to let a combo box or two be left blank at a stage when it is not in use. How can I get rid of the NullReferenceException?
Was This Post Helpful? 0
  • +
  • -

#17 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Saving ComboBoxes and TextBoxes to an Excel book

Posted 20 February 2013 - 01:03 PM

If you're just passing the text that is displayed in the combobox to the cell you could use Combobox1.Text instead of Combobox1.SelectedItem.ToString

This should produce and empty when nothing is selected.
Was This Post Helpful? 0
  • +
  • -

#18 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3467
  • View blog
  • Posts: 11,770
  • Joined: 12-December 12

Re: Saving ComboBoxes and TextBoxes to an Excel book

Posted 20 February 2013 - 01:24 PM

You can fill the range in one go:

oSheet.Range("A5:A18").Value = objExcel.WorksheetFunction.Transpose({ _
    ComboBox1.Text, ComboBox2.Text, ... etc..})

- ensure that there are the same number of ComboBox.Text values are there are cells in the range you are filling.

This post has been edited by andrewsw: 20 February 2013 - 01:26 PM

Was This Post Helpful? 0
  • +
  • -

#19 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

Re: Saving ComboBoxes and TextBoxes to an Excel book

Posted 06 March 2013 - 11:16 AM

View Postandrewsw, on 20 February 2013 - 01:24 PM, said:

You can fill the range in one go:

oSheet.Range("A5:A18").Value = objExcel.WorksheetFunction.Transpose({ _
    ComboBox1.Text, ComboBox2.Text, ... etc..})

- ensure that there are the same number of ComboBox.Text values are there are cells in the range you are filling.


I would just like the SaveDialog box thing please? :) At the moment, I have to specify in my coding where to save it. So it a user downloads my program, and tries to save it, it wont save. Thats why I need a SaveDialog Box...
Was This Post Helpful? 0
  • +
  • -

#20 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 57
  • View blog
  • Posts: 292
  • Joined: 22-August 11

Re: Saving ComboBoxes and TextBoxes to an Excel book

Posted 06 March 2013 - 11:28 AM

andrewsw kindly provided you with a link to information regarding SaveDialog.

View Postandrewsw, on 17 February 2013 - 05:41 AM, said:

What? The SaveFileDialog


I'd suggest you attempt the following, or some variation of it:

Step 1. Click the link andrewsw gave in his prior post.
Step 2. Read the information.
Step 3. Try some things and see how they work.
Step 4. If you figure it out, great work! Else, post the code with all of your tries so we can see.
Step 5. Read any responses given and answer them clearly and concisely. Provide relevant code if applicable.
Step 6. Stop asking "Gimme teh Codez" and learn.
Was This Post Helpful? 0
  • +
  • -

#21 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

Re: Saving ComboBoxes and TextBoxes to an Excel book

Posted 07 March 2013 - 11:07 AM

View Posttorind_2000, on 06 March 2013 - 11:28 AM, said:

andrewsw kindly provided you with a link to information regarding SaveDialog.

View Postandrewsw, on 17 February 2013 - 05:41 AM, said:

What? The SaveFileDialog


I'd suggest you attempt the following, or some variation of it:

Step 1. Click the link andrewsw gave in his prior post.
Step 2. Read the information.
Step 3. Try some things and see how they work.
Step 4. If you figure it out, great work! Else, post the code with all of your tries so we can see.
Step 5. Read any responses given and answer them clearly and concisely. Provide relevant code if applicable.
Step 6. Stop asking "Gimme teh Codez" and learn.


I have tried that coding from the example in the link, but I do not know HOW to implement it.... I tried to copy and past it, and debug it, but no Dialog opened...
Was This Post Helpful? 0
  • +
  • -

#22 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3467
  • View blog
  • Posts: 11,770
  • Joined: 12-December 12

Re: Saving ComboBoxes and TextBoxes to an Excel book

Posted 07 March 2013 - 11:12 AM

If you just copied and pasted the code, without understanding it, then it is not surprising that it didn't work. You need to read and study the information in the linked-page so that you can incorporate the example into your own code. If you do this and it still doesn't work then you could come back here, post your code, and someone will probably give you some guidance.

If you don't wish to study, and understand, the code then you might consider employing someone to create the code you need.
Was This Post Helpful? 0
  • +
  • -

#23 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

Re: Saving ComboBoxes and TextBoxes to an Excel book

Posted 08 March 2013 - 06:22 AM

View Postandrewsw, on 07 March 2013 - 11:12 AM, said:

If you just copied and pasted the code, without understanding it, then it is not surprising that it didn't work. You need to read and study the information in the linked-page so that you can incorporate the example into your own code. If you do this and it still doesn't work then you could come back here, post your code, and someone will probably give you some guidance.

If you don't wish to study, and understand, the code then you might consider employing someone to create the code you need.


I have tried to understand it, and I have asked questions to help me understand, but I still asked where is the coding that I already have to save all the comboboxes, and no one answered me... Everyone answered other stuff...
Was This Post Helpful? 0
  • +
  • -

#24 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9197
  • View blog
  • Posts: 34,551
  • Joined: 12-June 08

Re: Saving ComboBoxes and TextBoxes to an Excel book

Posted 08 March 2013 - 06:28 AM

Quote

[but I still asked where is the coding that I already have to save all the comboboxes,

I thought you had that working in post 9.
Was This Post Helpful? 0
  • +
  • -

#25 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Saving ComboBoxes and TextBoxes to an Excel book

Posted 08 March 2013 - 06:36 AM

No, he has a static line to save, he's wanting to prompt the user with the save file dialog so that from that he can get the

AHEM!!!
SaveFileDialog's .FileName property that returns a string of the path & file ;) to put in place of the string he's specifying
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2