473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Saving form submitted by user to Excel File

Hi all,

I'm new to Visual Basic/Studio 6. I have a small application form where I have to submit some information. All this is working fine and I'm able to write these information to an excel file.

I need now to write eg name to row 7 column A, surname to row 8 column B, etc. Currently it is writing the info submitted in the top left corner.

Any help will be appreciated.

Thanks
Oct 23 '06 #1
4 3076
albertw
267 100+
Hi all,

I'm new to Visual Basic/Studio 6. I have a small application form where I have to submit some information. All this is working fine and I'm able to write these information to an excel file.

I need now to write eg name to row 7 column A, surname to row 8 column B, etc. Currently it is writing the info submitted in the top left corner.

Any help will be appreciated.

Thanks
hi
try this
you may need to alter filenames
note that the code in not tested !
leave it to your imagination :)

Expand|Select|Wrap|Line Numbers
  1. Private appExel As Excel.Application
  2. Private wbBook As Excel.Workbook
  3.  
  4. Private Sub Form_Load()
  5.     Dim rngExelRange As Excel.Range
  6.     On Error Resume Next                                
  7.     Set appExel = GetObject(, "Excel.Application")
  8.     ' find out if Exel is running already
  9.     If Err.Number <> 0 Then  Set appExel = CreateObject("Excel.Application")
  10.     Err.Clear    
  11.     On Error GoTo Fail
  12.     ' this spreadsheet is called Sheet.xls
  13.     Set wbBook = appExel.Workbooks.Open(App.Path & "\Sheet.xls")
  14.     FreeNum = FreeFile
  15.     ' the datafile containing item to put into Sheets.xls is called Filename
  16.     Open Filename for Input as #FreeNum
  17.     Line Input #FreeNum, p
  18.     ' data in the file 'filename' is supposed to have a fixed sequence
  19.     ' from which you can take the induvidual data an put this in your
  20.     ' Exel worksheet
  21.     rngExelRange.Cells(7,1) = p         ' range("A7")
  22.     ' get next item 
  23.     Line Input #FreeNum, p
  24.     ' and put this in the worksheet
  25.     rngExelRange.Cells(8,2) = p         'range("B8")
  26. Fail:
  27.     Err.Clear
  28.     Close 
  29.     ' make things tidy
  30.     Set appExel = Nothing
  31.     Set wbBook = Nothing
  32. End Sub
  33.  
Oct 23 '06 #2
albertw
267 100+
hi
try this
you may need to alter filenames
note that the code in not tested !
leave it to your imagination :)

Expand|Select|Wrap|Line Numbers
  1. Private appExel As Excel.Application
  2. Private wbBook As Excel.Workbook
  3.  
  4. Private Sub Form_Load()
  5.     Dim rngExelRange As Excel.Range
  6.     On Error Resume Next                                
  7.     Set appExel = GetObject(, "Excel.Application")
  8.     ' find out if Exel is running already
  9.     If Err.Number <> 0 Then  Set appExel = CreateObject("Excel.Application")
  10.     Err.Clear    
  11.     On Error GoTo Fail
  12.     ' this spreadsheet is called Sheet.xls
  13.     Set wbBook = appExel.Workbooks.Open(App.Path & "\Sheet.xls")
  14.     FreeNum = FreeFile
  15.     ' the datafile containing item to put into Sheets.xls is called Filename
  16.     Open Filename for Input as #FreeNum
  17.     Line Input #FreeNum, p
  18.     ' data in the file 'filename' is supposed to have a fixed sequence
  19.     ' from which you can take the induvidual data an put this in your
  20.     ' Exel worksheet
  21.     rngExelRange.Cells(7,1) = p         ' range("A7")
  22.     ' get next item 
  23.     Line Input #FreeNum, p
  24.     ' and put this in the worksheet
  25.     rngExelRange.Cells(8,2) = p         'range("B8")
  26. Fail:
  27.     Err.Clear
  28.     Close 
  29.     ' make things tidy
  30.     Set appExel = Nothing
  31.     Set wbBook = Nothing
  32. End Sub
  33.  
hi again
second best option is to create a .csv (comma separated values) file
disadvantage of such a file is that data must be entered in a sequence.

Open App.Path & "\Exel.csv" for output as #1
Print #1,Value1;",";Value2;",";Value3
Close #1

the amount of commas between values will determine the column
every new Print #1 statement determines the row.
Oct 24 '06 #3
Thanks for the reply - please ignore first question about excel - is actually word document.

I have a form (see below) with 2 text fields and a submit button. I can save data to the file but in sequence below each other. What I want to do is: to open an existing word document (a form that I usually print out and fill in information required manually with a pen). The existing contents of the file is something like:

Hello, my name is _______ and my surname is _______!!

The existing word file may contain blocks, tables, lines, etc.

Instead to write it with a pen, the vb application must open up this file and enter the name and surname fields from the form.

Almost like PHP where I use variables eg.

Hello, my name is $name and my surname is $surname!!

And will it be possible and easy to save the file as the name entered by user instead of using a fixed filename?


[PHP]

Private Sub Command1_Click()
Dim hFile As Long
Dim sFilename As String

sFilename = "f:\mac.xls"

'obtain the next free file handle from the
'system and and save the text box contents
hFile = FreeFile
Open sFilename For Output As #hFile
Print #hFile, ("Name: "), Text1.Text
Print #hFile, ("Surname: "), Text2.Text

Close #hFile

Unload Me

MsgBox "Thanks for submitting your MAC address"
End Sub

[/PHP]
Oct 24 '06 #4
albertw
267 100+
Thanks for the reply - please ignore first question about excel - is actually word document.

I have a form (see below) with 2 text fields and a submit button. I can save data to the file but in sequence below each other. What I want to do is: to open an existing word document (a form that I usually print out and fill in information required manually with a pen). The existing contents of the file is something like:

Hello, my name is _______ and my surname is _______!!

The existing word file may contain blocks, tables, lines, etc.

Instead to write it with a pen, the vb application must open up this file and enter the name and surname fields from the form.

Almost like PHP where I use variables eg.

Hello, my name is $name and my surname is $surname!!

And will it be possible and easy to save the file as the name entered by user instead of using a fixed filename?


[PHP]

Private Sub Command1_Click()
Dim hFile As Long
Dim sFilename As String

sFilename = "f:\mac.xls"

'obtain the next free file handle from the
'system and and save the text box contents
hFile = FreeFile
Open sFilename For Output As #hFile
Print #hFile, ("Name: "), Text1.Text
Print #hFile, ("Surname: "), Text2.Text

Close #hFile

Unload Me

MsgBox "Thanks for submitting your MAC address"
End Sub

[/PHP]
sry, no experience in programming where word is involved.
Oct 24 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Vikram | last post by:
Hi, Given below is my task. An user can open the xls file from my website (loaded on the top frame). After filling the Excel, he can click a send button at the bottom frame. By clicking the...
0
by: mathieu cupryk | last post by:
in the Button1_Click I need to make the 1st column saved as readonly. How can I do this? using System; using System.Collections; using System.ComponentModel; using System.Data; using...
0
by: Luis Esteban Valencia | last post by:
in the Button1_Click I need to make the 1st column saved as readonly. How can I do this? using System; using System.Collections; using System.ComponentModel; using System.Data; using...
13
by: =?Utf-8?B?emlyb3M=?= | last post by:
We have a need, after a user fill out a form, to save that page (aspx) and to send it as attachment by email , and to save it to a database for later retrieval any ideas how to save the aspx...
3
by: roseredphoenix | last post by:
Can anyone help me with a form I'm trying to make? I'm trying to make a submission form for my school's literary magazine. I need to put the submitted information into a database. I know I need to...
6
by: Karl | last post by:
Hi all, It may seem like a rather odd request (or not) but I would like to be able to create a file (doc, jpg, xls or one of many other files that can be automated) on a website and stream it to...
3
by: pozze | last post by:
Hi, I've just made the change from ASP to .net. I have a file (code below) that saves a user submitted file to a MS SQL 2005 database. It collects the file name, file size, file type, and lastly...
6
by: Eddie | last post by:
Hi all, I am displaying a number of reports, and giving the users an option to display them on the web or download them to Excel. If they want the Excel file, I just use the PHP header command...
16
by: blaze77 | last post by:
Hi, I'm somewhat of a power user in excel and a newbie to Access though the possibilities are exciting me :-) I am trying to create a tool in Access to replace an existing tool in Excel. My...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.