Please how can i import and print contents of Excel?
Please how can i import and print contents of Excel?
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
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
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.
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.
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.
Please I need vb6 source codes not commercial applications.
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
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 < 100 Then pnlIndicador.Value = VLPorcentaje VGGridExporta.row = VLContadorR VLLinea = "" If VGGridExporta.RowHeight(VLContadorR) <> 0 Then ' omite los invisibles For VLContadorCE = 1 To grdCampos.Rows - 1 grdCampos.row = VLContadorCE If optFija Then If Len(grdCampos) > 0 Then grdCampos.Col = 0 VGGridExporta.Col = Val(Trim$(Mid$(grdCampos, 2, 2))) VLLenGrid = Len(Trim(VGGridExporta)) grdCampos.Col = 1: VLLenUsuario = grdCampos If VLLenUsuario > 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) > 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
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
"
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.
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.
Bookmarks