Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 04-07-2009
Member
 
Join Date: Jul 2009
Posts: 6
Import excel file and print

Please how can i import and print contents of Excel?
Reply With Quote
  #2  
Old 04-07-2009
Member
 
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
Reply With Quote
  #3  
Old 04-07-2009
Member
 
Join Date: May 2008
Posts: 3,313
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
Reply With Quote
  #4  
Old 04-07-2009
Member
 
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.
Reply With Quote
  #5  
Old 04-07-2009
Member
 
Join Date: May 2008
Posts: 2,008
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.
Reply With Quote
  #6  
Old 04-07-2009
Member
 
Join Date: May 2008
Posts: 3,313
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.
Reply With Quote
  #7  
Old 04-07-2009
Member
 
Join Date: Jul 2009
Posts: 6
Re: Import excel file and print

Please I need vb6 source codes not commercial applications.
Reply With Quote
  #8  
Old 04-07-2009
XSI XSI is offline
Member
 
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
Reply With Quote
  #9  
Old 04-07-2009
Member
 
Join Date: May 2008
Posts: 2,383
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
Reply With Quote
  #10  
Old 04-07-2009
Member
 
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
"
Reply With Quote
  #11  
Old 04-07-2009
Member
 
Join Date: May 2008
Posts: 2,383
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.
Reply With Quote
  #12  
Old 04-07-2009
XSI XSI is offline
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Import excel file and print"
Thread Thread Starter Forum Replies Last Post
How can I print a file to Excel instead using Printer Marg!Aret MS Office Support 2 27-01-2012 04:16 PM
Need Macro command to print and email a pdf file in Microsoft Excel Tritanic MS Office Support 3 25-01-2012 12:03 PM
How to import a .xps file in Microsoft Excel 2007 The-Farmer MS Office Support 2 17-01-2012 01:24 PM
Need help to import a Microsoft Excel file to semicolon delimited text file Roch Windows Software 5 13-01-2012 05:18 PM
Some files of Excel not print in Windows 7 but the same get print in Vista Obessed Windows Software 3 26-11-2010 02:52 AM


All times are GMT +5.5. The time now is 04:31 AM.