I am Happy to meet you all
I am learning Visual Basic now.
Thru Visual Basic 6.0, Can we create an Excel file using a Template file which is in my local Drive and passing some values to that file, and finally saving it as a different name (Which is not my Template file's Name) at different location.
Here is the code, which I got from one site. ( slightly modified )
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
'Add data to cells of the first worksheet in the new workbook
oSheet = oBook.Worksheets(1)
oSheet.Range("A1").Value = "S.No."
oSheet.Range("B1").Value = "Description"
oSheet.Range("A1:B1").Font.Bold = True
oSheet.Range("A2").Value = "1"
oSheet.Range("B2").Value = "Nothing"
'Save the Workbook and Quit Excel
oBook.SaveAs("D:\BOMS\200378_BOM.xls")
oExcel.Quit()
Thank you very very much, Kenny and Rog,
Greatly, it is working.
Could you please give me a hint, How to link to Excel cells with my GUI Textbox.
I already prepared my GUI and the great thing is to link the TEXTBOX's with my Excel file's CELL's.
For example ...
oSheet.Range("c12").Value = "202154-A-4587"
Here, the Value for "c12" is a string, instead of a string I would like to link this CELL with my "form1.vb" textbox "PART NAME".
I am apologized for the Incomplete question.
Here once I press Next, the entire data should be passed to the respective excel sheet and the dialog again prompt me to do the same, until unless it is cancelled.
Is this possible to make it as loop ?
do you have something else tied in to this? So you want the form to view each sheets data for read/write?
Use the oBook.Sheets("Sheet2").Select method for switching the view of the sheet. Just reference which sheet you are going to be reading/writting to/from.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Dear Rob,
I am trying to give a LOOP condition, so that once all the values are passed to excel Sheet's FIRST ROW, then agian it should prompt the user to enter the same values for the SECOND ROW.
This should happen until unless I CANCEL my GUI, Because I am having so many parts to enter them with their details as shown in the previous attachment.
Hope you understood my intension.
Thanking you,
Alan
Dear Rob,
I might not able to frame my query in a proper way, I suppose.
really, I tried so many times, I searched some sites and finally I failed at this point. Please find the attachment named "Query.jpg".
'Add data to cells of the first worksheet in the new workbook
oSheet = oBook.Worksheets(1)
oSheet.Range("d3").Value = Form2.TextBox1.Text
oSheet.Range("d4").Value = Form2.TextBox2.Text
oSheet.Range("d5").Value = Form2.TextBox3.Text
oSheet.Range("N2").Value = Form2.TextBox4.Text
oSheet.Range("o6").Value = Form2.TextBox5.Text
If Me.RadioButton1.Checked = True Then
oSheet.Range("k10").Value = Form2.TextBox3.Text
oSheet.Range("l10").Value = Form2.TextBox3.Text
End If
If Me.RadioButton2.Checked = True Then
oSheet.Range("k10").Value = Form2.TextBox3.Text
oSheet.Range("l10").Value = "00"
End If
'some times I may get only "5 Parts" and sometimes it might be around 200.
'hence each time I am not able to declare the Range for each textbox.
' Here I need to get REPEATEDLY the current form when I click "NEXT"
' to enter varied values of "Part No.", "Description", "Assy No" for ROW-2 and again for ROW-3 and again for ROW-4 ... 5 ... 6..
' and when I click "OK" the data should pass into my worksheet.
i define with SET statement but i found error message "compile error : invalid outside procedure",sorry i'm still newbie and i 'm very happy if you will guide me more :Big Green: