VB6 to Excel

In my previous tutorials, I had discussed about how to have an excel file using vb.net. And for now, we will create a program that can have an excel file from vb6. Now, let's start this tutorial! 1.Let's start this tutorial by following the following steps in Microsoft Visual Basic 6.0: Open Microsoft Visual Basic 6.0, click Choose Standard EXE, and click Open. 2. Next, add two TextBox named Text1 and Text2 for inputting and displaying it in excel. Add also one button named Command1 for displaying it in an excel file. You must design your interface like this: design 3. Now put this code for your code module. This code is for Button1_Click:
  1. Private Sub Command1_Click()
  2. Dim appExcel As Excel.Application
  3. Dim appWB As Excel.Workbook
  4. Dim appWS As Excel.Worksheet
  5.  
  6. Set appExcel = Excel.Application
  7.  
  8. appExcel.Visible = True
  9. Set appWB = appExcel.Workbooks.Add
  10. Set appWS = appWB.Worksheets("Sheet1")
  11. appExcel.Sheets("Sheet1").Cells(1, 2).Font.Bold = True
  12. appExcel.Sheets("Sheet1").Cells(1, 2).Font.Name = "Verdana"
  13. appExcel.Sheets("Sheet1").Cells(1, 2).Font.Color = &H80&
  14. appExcel.Sheets("Sheet1").Cells(1, 2).Font.Italic = &H80&
  15. appExcel.Sheets("Sheet1").Cells(1, 1) = Text1.Text
  16. appExcel.Sheets("Sheet1").Cells(1, 2) = Text2.Text
  17. appExcel.Visible = True
  18. End Sub

Explanation:

We have initialized variable appExcel As Excel.Application, appWB As Excel.Workbook, and appWS As Excel.Worksheet. Then we set appExcel to hold an Excel Application, appWB will add an excel workbook of appExcel, and appWS to hold a worksheet out from appWB and named it as Sheet1. Then, the appExcel sheets in sheet1 in cells(rows,columns) of the worksheets and has methods like fonts and its aattributes such as Bold, Name, Color, and Italic. Our Text2 will be our basis that it is bold, in verdana font style, has a font color of a reddish color, and is italic because they have same cells of 1,2.

Output:

outputoutput Download the source code and try it! :) For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon R. Bermoy IT Instructor/System Developer/Android Developer STI College - Surigao City Mobile: 09488225971 E-mail:[email protected] Follow and add me in my Facebook Account: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Comments

Submitted byAnonymous (not verified)on Mon, 02/27/2023 - 21:33

Thx a lot

Add new comment