Results 1 to 12 of 12

Thread: Import excel file and print

  1. #1
    Join Date
    Jul 2009
    Posts
    6

    Import excel file and print

    Please how can i import and print contents of Excel?

  2. #2
    Join Date
    Apr 2008
    Posts
    2,139

    Re: Import excel file and print

    Check the following threads. Here, you will find the solution for importing the data in Excel and also printing data from Excel file.

    How do i import Excel data from password protected site

    Printing in Excel 2007

  3. #3
    Join Date
    May 2008
    Posts
    3,316

    Re: Import excel file and print

    Printing in Excel is little different than printing in some other programs, such as a Word Processor. Excel has 5 locations in the program that contain print-related options. First is the Print button which is located on the standard toolbar. Other 4 are listed under the File menu: Print Preview, Page Setup, Print Area and Print

  4. #4
    Join Date
    Jul 2009
    Posts
    6

    Re: Import excel file and print

    Sorry. I meant how to import data from excel using visual basic 6 and printing the data.

    We have a need to print contents of excel using vb6.
    We want to print each row in excel on a single A4 paper.

  5. #5
    Join Date
    May 2008
    Posts
    2,012

    Re: Import excel file and print

    Check out Print Helper 2.0 for automates printing or conversion process. You can select all the documents that require printing and processed at once. Converter converts any type of file to image formats including TIFF.

  6. #6
    Join Date
    May 2008
    Posts
    3,316

    Re: Import excel file and print

    To Print,click Quick Print and bring Print Preview the to see the output if you are fine with that just print it by selecting Print.
    else for additional features like Themes, Page Setup, Scale to Fit, Sheet Options, and Arrange:
    Select Page Layout
    For Normal view, Page layout View, Page Break Preview, and Custom Views:
    Select View > Workbook Views Group.

  7. #7
    Join Date
    Jul 2009
    Posts
    6

    Re: Import excel file and print

    Please I need vb6 source codes not commercial applications.

  8. #8
    Join Date
    May 2008
    Posts
    271

    Re: Import excel file and print

    The below code will allow you to select the content on the Excel worksheet and print them using VB6:

    Code:
    Option Explicit
    Sub SelectSheets()
       Dim i As Integer
       Dim FirstPos As Integer
       Dim SheetCount As Integer
       Dim PrintDlg As DialogSheet
       Dim CurrentSheet As Worksheet
       Dim cb As CheckBox
       Application.ScreenUpdating = False
       If ActiveWorkbook.ProtectStructure Then
           MsgBox "Workbook is protected.", vbCritical
           Exit Sub
       End If
       Set CurrentSheet = ActiveSheet
       Set PrintDlg = ActiveWorkbook.DialogSheets.Add
       SheetCount = 0
       FirstPos = 40
       For i = 1 To ActiveWorkbook.Worksheets.Count
           Set CurrentSheet = ActiveWorkbook.Worksheets(i)
           If Application.CountA(CurrentSheet.Cells) <> 0 And CurrentSheet.Visible Then
               SheetCount = SheetCount + 1
               PrintDlg.CheckBoxes.Add 78, TopPos, 150, 16.5
                   PrintDlg.CheckBoxes(SheetCount).Text = _
                       CurrentSheet.Name
               FirstPos = FirstPos + 13
           End If
       Next i
       PrintDlg.Buttons.Left = 240
       With PrintDlg.DialogFrame
           .Height = Application.Max (68, PrintDlg.DialogFrame.Top + FirstPos - 34)
           .Width = 230
           .Caption = "Select sheets to print"
       End With
       PrintDlg.Buttons("Button 2").BringToFront
       PrintDlg.Buttons("Button 3").BringToFront
       CurrentSheet.Activate
       Application.ScreenUpdating = True
       If SheetCount <> 0 Then
               If PrintDlg.Show Then
                   For Each cb In PrintDlg.CheckBoxes
                       If cb.Value = xlOn Then
                           Worksheets(cb.Caption).Select Replace:=False
                       End If
       Next cb
           ActiveWindow.SelectedSheets.PrintOut copies:=1
           ActiveSheet.Select
       End If
       Else
           MsgBox "All worksheets are empty."
       End If
       Application.DisplayAlerts = False
       PrintDlg.Delete
       CurrentSheet.Activate
    End Sub

  9. #9
    Join Date
    May 2008
    Posts
    2,389

    Import excel file and print

    Try to use the following code hope this should work for you.

    Code:
    VLSeparador = cmb_Separador
    If cmb_Separador = "TAB" Then VLSeparador = Chr$(9)
    VLArchivo = FreeFile
    Open txtArchivo For Output As #VLArchivo
    VLEstado = 1
    VLMaxLineas = VGGridExporta.Rows - 1
    grdCampos.Enabled = False 'Para evitar refresh
    For VLContadorR = VGGridExporta.FixedRows To VGGridExporta.Rows - 1
        VLPorcentaje = 100 * VLContadorR / VLMaxLineas
        If VLPorcentaje &lt; 100 Then pnlIndicador.Value = VLPorcentaje
    
        VGGridExporta.row = VLContadorR
        VLLinea = ""
        If VGGridExporta.RowHeight(VLContadorR) &lt;&gt; 0 Then ' omite los invisibles
            For VLContadorCE = 1 To grdCampos.Rows - 1
              grdCampos.row = VLContadorCE
                 If optFija Then
                     If Len(grdCampos) &gt; 0 Then
                         grdCampos.Col = 0
                         VGGridExporta.Col = Val(Trim$(Mid$(grdCampos, 2, 2)))
                         VLLenGrid = Len(Trim(VGGridExporta))
                         grdCampos.Col = 1: VLLenUsuario = grdCampos
                         If VLLenUsuario &gt; VLLenGrid Then
                             VLLinea = VLLinea & Trim(VGGridExporta) & Space(VLLenUsuario - Len(Trim(VGGridExporta)))
                         Else
                             VLLinea = VLLinea & Left$(Trim(VGGridExporta), VLLenUsuario)
                         End If
                     Else
                         Exit For
                     End If
                 Else
                     If Len(grdCampos) &gt; 0 Then
                         VGGridExporta.Col = Val(Trim$(Mid$(grdCampos, 2, 2)))
                         VLLinea = VLLinea & Trim(VGGridExporta) & VLSeparador
                     Else
                         Exit For
                     End If
                 End If
    
            Next
        If Not optFija Then VLLinea = Left(VLLinea, Len(VLLinea) - 1)
          Print #VLArchivo, VLLinea
          DoEvents
          If VLDetener Then
              Close #VLArchivo
              If Not VLGuardardatos Then
                Kill txtArchivo
              End If
              MsgBox LoadResString(504), vbInformation + vbOKOnly, Screen.ActiveForm.Caption
              grdCampos.Enabled = True
              cmdCancelar.Enabled = True
              cmdSiguiente.Caption = LoadResString(31)
              VLIniciar = True
              VLDetener = False
              pnlIndicador.Value = 0
    
              Exit Sub
          End If
        End If
    Next
    grdCampos.Enabled = True
    pnlIndicador.Value = 100
    Close #VLArchivo
    MsgBox LoadResString(506), vbInformation + vbOKOnly, Screen.ActiveForm.Caption

  10. #10
    Join Date
    Jul 2009
    Posts
    6

    Re: Import excel file and print

    Where should I put the code?
    In a Button Control?


    "Option Explicit
    Sub SelectSheets()
    Dim i As Integer
    Dim FirstPos As Integer
    Dim SheetCount As Integer
    Dim PrintDlg As DialogSheet
    Dim CurrentSheet As Worksheet
    Dim cb As CheckBox
    Application.ScreenUpdating = False
    If ActiveWorkbook.ProtectStructure Then
    MsgBox "Workbook is protected.", vbCritical
    Exit Sub
    End If
    Set CurrentSheet = ActiveSheet
    Set PrintDlg = ActiveWorkbook.DialogSheets.Add
    SheetCount = 0
    FirstPos = 40
    For i = 1 To ActiveWorkbook.Worksheets.Count
    Set CurrentSheet = ActiveWorkbook.Worksheets(i)
    If Application.CountA(CurrentSheet.Cells) <> 0 And CurrentSheet.Visible Then
    SheetCount = SheetCount + 1
    PrintDlg.CheckBoxes.Add 78, TopPos, 150, 16.5
    PrintDlg.CheckBoxes(SheetCount).Text = _
    CurrentSheet.Name
    FirstPos = FirstPos + 13
    End If
    Next i
    PrintDlg.Buttons.Left = 240
    With PrintDlg.DialogFrame
    .Height = Application.Max (68, PrintDlg.DialogFrame.Top + FirstPos - 34)
    .Width = 230
    .Caption = "Select sheets to print"
    End With
    PrintDlg.Buttons("Button 2").BringToFront
    PrintDlg.Buttons("Button 3").BringToFront
    CurrentSheet.Activate
    Application.ScreenUpdating = True
    If SheetCount <> 0 Then
    If PrintDlg.Show Then
    For Each cb In PrintDlg.CheckBoxes
    If cb.Value = xlOn Then
    Worksheets(cb.Caption).Select Replace:=False
    End If
    Next cb
    ActiveWindow.SelectedSheets.PrintOut copies:=1
    ActiveSheet.Select
    End If
    Else
    MsgBox "All worksheets are empty."
    End If
    Application.DisplayAlerts = False
    PrintDlg.Delete
    CurrentSheet.Activate
    End Sub
    "

  11. #11
    Join Date
    May 2008
    Posts
    2,389

    Re: Import excel file and print

    You need to insert this code into Control Button only or else you can make a new button in that you can paste the following code.

  12. #12
    Join Date
    May 2008
    Posts
    271

    Re: Import excel file and print

    You can put this code on multiple places. If you have any script which is performing some functions using VB codes then you can put this code there. Otherwise if you want then you can put this code on a Notepad and save it as *.vb. Run this while the Excel file is open. You can also put a button on your Excel worksheet naming it "Print" and put the code for it.

Similar Threads

  1. How can I print a file to Excel instead using Printer
    By Marg!Aret in forum MS Office Support
    Replies: 2
    Last Post: 27-01-2012, 04:16 PM
  2. Replies: 3
    Last Post: 25-01-2012, 12:03 PM
  3. How to import a .xps file in Microsoft Excel 2007
    By The-Farmer in forum MS Office Support
    Replies: 2
    Last Post: 17-01-2012, 01:24 PM
  4. Replies: 5
    Last Post: 13-01-2012, 05:18 PM
  5. Replies: 3
    Last Post: 26-11-2010, 02:52 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,566,216.45815 seconds with 17 queries