Results 1 to 3 of 3

Thread: Printing in VB6

  1. #1

    Thread Starter
    Addicted Member waelr's Avatar
    Join Date
    Nov 2004
    Posts
    168

    Printing in VB6

    hey guys im using the following code to print contents of a flexgrid and some textboxes
    im exporting the data to an excel file and then printing it
    VB Code:
    1. Set xlApp = CreateObject("Excel.Application")
    2.     Set xlBook = xlApp.Workbooks.Add
    3.     Set xlSheet = xlBook.Worksheets(1)
    4.     xlBook.Worksheets(3).Delete
    5.     xlBook.Worksheets(2).Delete
    6.    
    7.     With xlSheet
    8.             .PageSetup.Orientation = 2
    9.             .PageSetup.LeftMargin = 0
    10.             .PageSetup.TopMargin = 0
    11.             .Cells.WrapText = False
    12.             .Cells.Font.Size = 8
    13.            
    14.             Dim dt
    15.             dt = Date
    16.             .Range("A1").ColumnWidth = 3
    17.             .Range("B1").ColumnWidth = 13
    18.             .Range("C1").ColumnWidth = 6
    19.             .Range("B1").Value = dt
    20.             .Range("A2").Value = "Name"
    21.             .Range("A2").Font.Name = "Monotype Corsiva"
    22.             .Range("A2").Font.Size = 14
    23.             .Range("A3").Value = "Address1"
    24.             .Range("A3").Font.Bold = True
    25.             .Range("A4").Value = "Address2"
    26.             .Range("A4").Font.Bold = True
    27.             .Range("A5").Value = "Phone Number"
    28.             .Range("A5").Font.Bold = True
    29.            
    30.             .Range("A6").Value = "Cashier: " & FormStart.Text1
    31.             .Range("A6").Font.Bold = True
    32.            
    33.             .Range("A7").Value = "Invoice #: " & Text4
    34.             .Range("A7").Font.Bold = True
    35.             .Range("A8").Value = Combo1.Text
    36.             .Range("A8").Font.Bold = True
    37.            
    38.             .Range("A9").Value = "----------------------------------------"
    39.             .Range("A10").Value = "Qty"
    40.             .Range("A10").Font.Bold = True
    41.             .Range("B10").Value = "Item"
    42.             .Range("B10").Font.Bold = True
    43.             .Range("C10").Value = "Price"
    44.             .Range("C10").Font.Bold = True
    45.             .Range("A11").Value = "----------------------------------------"
    46.            
    47.             For i = 1 To MSF.Rows - 1
    48.                 For j = 1 To 3
    49.                 xlSheet.Cells(11 + i, j) = MSF.TextMatrix(i, j - 1)
    50.                 Next j
    51.             Next i
    52.             k = 11 + i
    53.             .Range("A" & k).Value = "Discount"
    54.             .Range("A" & k).Font.Bold = True
    55.             .Range("C" & k).Value = Text2 & " %"
    56.             k = k + 2
    57.             .Range("B" & k).Value = "TOTAL " & Text1 & " $"
    58.             .Range("B" & k).Font.Size = 12
    59.             .Range("B" & k).Font.Bold = True
    60.  
    61.     End With
    62.  
    63.     xlApp.Visible = False
    64.  
    65.     'xlSheet.PrintOut (1)
    66.     Dim y
    67.     y = "Sample.xls"
    68.     xlSheet.SaveAs (y)
    69.     xlApp.Workbooks.Close


    I attached the "Sample.xls" file
    how can i get the same result using the VB6 Data Report or Crystal Reports 9
    Attached Files Attached Files

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Printing in VB6

    That could be done using those reporting tools, find some examples for you to learn from, perhaps something here might get you started...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Printing in VB6

    If you use CR 9 with VB6 you can use the CR Viewer control to display the report on your form. Then include and enable the Export button. If you distribut the support files for exporting excel format, you can export with a simple button click and not event need Excel installed on the system, unless you want to open excel and view it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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